Regex Word Boundary (\b) Explained
The \b anchor matches the position between a word character and a non-word character, without consuming any characters itself.
Published October 12, 2026
The \b anchor matches the position between a word character and a non-word character, without consuming any characters itself.
Key points
- \bcat\b matches "cat" as a whole word but not "category" or "scatter"
- Word boundaries are based on \w (letters, digits, underscore) versus everything else
Example
\bcat\b