I was wondering if anyone could give me use cases when it is impossible to do without \ b.
The expression \b is just a convenient shorthand for what you can already do with other constructs.
For example, if your regex engine has lookarounds, then \b equivalent to the following longer expression:
(?<=\w)(?!\w)|(?<!\w)(?=\w)
Similar to \w , \d , etc. they simply cut back on what can already be done using character classes such as [A-Za-z0-9_] or [0-9] . Usually you want to use the short version, because each time the full definition is cumbersome, difficult to read, and increases the risk of error.
source share