Andy Jarrett // Code. Develop. Create.

RegEx word boundaries

Recently I was looking for the word "fail" or "pass" in a string so I had the following regEx set up:#reFindNoCase("pass|fail", status)#Which worked fine until testing came along and "failed" got passed through successfully. To prevent this you need to use regex boundaries, "\\b", so my new statement becomes:#reFindNoCase("\\bpass\\b|\\bfail\\b", status)#In simple terms "\\b" perform a "whole word only" search means that it trapped 'failed', 'failure' you get the point.

I’m here, learning and working away. If you liked this content and want to keep me going, consider buying me a coffee. Your support keeps this site running and the coffee brewing! ☕️