Php regex can use word boundary character (\b) to match a word boundary. Beginning of string if following by a word character will also match word boundary. Similarly end of string will also match a word boundary if immediately preceded by a word character (alphanumeric or underscore).