I think a better explanation of why \b can be used as both a "lookahead" and a "lookbehind" assertion, is that not only is it zero-width in terms of the number of places it advances the current pointer as is the case with (?=), (?!), (?<=) & (?<!).
It is also "zero-width" in terms of the number of characters it matches, which the others aren't.
That is to say, \b doesn't match characters, it matches the transition between two characters. And the transition being measured is always a straight comparison between the character before the pointer and the character after, only the sense of the comparison is changes.
Thus, \b is neither a lookahead nor a lookbehind assertion, it's more a "lookhere" or maybe "lookbetween" assertion.
As an interesting exercise to prove that \b is neither a lookahead nor a lookbehind assertion, try creating one of either than can be used as a substitute for \b.
I realise that my explanation will probably not fit anyone elses mental model, but it works for me:)
In reply to Re: Why do zero width assertions care about lookahead/behind?
by BrowserUk
in thread Why do zero width assertions care about lookahead/behind?
by davido
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |