You already now the beginning ^
and the end $
anchors.
They match either the beginning or the end of a text or line (with the m flag).
But if you want to anchor to a word boundary?
That’s where the \b
anchor comes in.
The \b
anchor matches the position between a word character and a non-word character.
For example:
\ba
matches every word that starts with an a
a\b
matches every word that ends with an a
The opposite also exists:
\B
matches the position between two characters that are not a word boundary
Match the first and last character of every word