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);
$poswords
in your regular expression with the actual value that doesn't work as expecte - zerkms 2012-04-04 21:16
foo,bar,baz
as a comma separated list there. And I'd better wait another couple of minutes rather than guessing and wasting time for unreal case ;- - zerkms 2012-04-04 21:18
\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
not
as a word, use \bnot\b
with no spaces in that expression. That will match not
with a non-word character before n
and after t
. That could be a fullstop, space, hash sign.. - Andrew Leach 2012-04-04 21:34
$poswords
- zerkms 2012-04-04 21:14