Match Whole Words
Word boundary
\b<word>\b
matches a whole word
\b
strictly matches the following positions:
Before the first character in subject string
After the last character in subject string
Between a word character and a character that is not a word character in subject string
\b<wordchar>
and<nonwordchar>\b
only match at the start of a word<wordchar>\b
and\b<nonwordchar>
only match at the end of a word\b<wordchar>\b
and\b<nonwordchar>\b
match nothing
Nonboundary
\B
strictly matches the following positions:
- Before the first character in subject string if it's not a word character
- After the last character in subject string if it's not a word character
- Between two word characters
- Between two nonword characters
- Empty string