What’s a word boundary in Regex?
12 April 2025 (Updated 18 May 2025)
In a nutshell
A word boundary is a special anchor in Regex that matches the position between a word character ([A-Za-z0-9_]) and a non-word character. It’s written as:
\b
For example, given this string:
"hello there!"
\bhello\b will match "hello" because:
"hello"has a word boundary before it (the start or end of strings are considered a boundary).- And a space after it (a space is a non-word character).
Tagged:
Regex