0

I have not used Regex much before.

\bcat\b will not match cat in _cat. I see that _ is non-word char and c is word char. Hence, I think the cat in _cat should be matched. But, in below forum, it says it is not.

http://www.rexegg.com/regex-boundaries.html#wordboundary

Didn't quite understand the reason behind it.

SynozeN Technologies
  • 1,337
  • 1
  • 14
  • 19
Vicky
  • 624
  • 2
  • 12
  • 35

1 Answers1

1

The \b anchor specifies that the match must occur on a boundary between a word character (the \w language element) and a non-word character (the \W language element). Word characters consist of alphanumeric characters and underscores; a non-word character is any character that is not alphanumeric or an underscore. (For more information, see Character Classes.) The match may also occur on a word boundary at the beginning or end of the string.

And the four characters in "_cat" are all word character, which match \w. See Character Classes: https://msdn.microsoft.com/en-us/library/20bw873z(v=vs.110).aspx

treesong
  • 193
  • 7