Reputation: 31
I have a method that looks for the word 'not' and then a word after it but if i have a sentence such as:
this is good. Not good
for some reason the 'not' will not be picked up due to the full stop that is in front of it, anyone know how to get around this, the code is below
preg_match_all("/(?<=\b not\b)\b good\b/i", $find, $matches);
Upvotes: 1
Views: 403
Reputation: 12973
\b
matches a word boundary, which is the position between two characters where one is a word character and one is not. Word characters are [a-zA-Z0-9]
. You are matching a word boundary before a space before the not
, and there isn't a word boundary there because the string has a full-stop as the previous character.
That is, there isn't word boundary between a full-stop and space, because neither is a word character.
More info: http://www.regular-expressions.info/wordboundaries.html
Upvotes: 2