Regular Expressions Word Boundary Match complete word


Example

\bfoo\b

will match the complete word with no alphanumeric and _ preceding or following by it.

Taking from regularexpression.info

There are three different positions that qualify as word boundaries:

  1. Before the first character in the string, if the first character is a word character.
  2. After the last character in the string, if the last character is a word character.
  3. Between two characters in the string, where one is a word character and the other is not a word character.

The term word character here means any of the following

  1. Alphabet([a-zA-Z])
  2. Number([0-9])
  3. Underscore _

In short, word character = \w = [a-zA-Z0-9_]