Please help with correct regexp

I have to check if the substring exist in the someString. First, I tried to solve the problem in the following way. someString.contains(substring).but it’s not worked as expected, if i tried to find word “ours” and there was “hours” I got “true” … Now I am using regexp “\b(substring )\b” , it’s work nice, but if someSting contains something like U.S. N.Y. and i am trying to check if this substring (with dots) exist - I get false.

Please help me improve regexp. Thank you

Hi,
1/ the dot (.) in the searched substring must be escaped by backslash (\) i.e. “U\.S\.”
2/ this regex shall work for both “ours” and “U.S.” - \b(substring)(\b|\B)
3/ finally - you could use https://regex101.com/ for regex testing

Cheers

2 Likes

Thank you!!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.