How exactly do Regular Expression word boundaries work in PHP?

The word boundary \b matches on a change from a \w (a word character) to a \W a non word character. You want to match if there is a \b before your @ which is a \W character. So to match you need a word character before your @

something@nimal
        ^^

==> Match because of the word boundary between g and @.

something!@nimal
         ^^ 

==> NO match because between ! and @ there is no word boundary, both characters are \W

Leave a Comment