Regular Expressions Word Boundary Find patterns at the beginning or end of a word


Example

Examine the following strings:

foobarfoo
bar
foobar
barfoo
  • the regular expression bar will match all four strings,
  • \bbar\b will only match the 2nd,
  • bar\b will be able to match the 2nd and 3rd strings, and
  • \bbar will match the 2nd and 4th strings.