Regex for checking word – Stack Overflow

(?i) enables case-insensitive matching. If you want to match OBS but not obs or Obs, remove it and it will solve your problem.

Another solution would be to use word boundaries (b) which will let you make sure you are matching full words : bOBSb

Moreover, I don’t think you want to use ^ and $ anchors in your context, they respectively match the start and the end of the string.

All in all, I’d use the following regex to match a string that contains “OBS” at some point :


You can try it online.

Read more here: Source link