PHP recognizing a full stop before a word

Go To


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);
2012-04-04 21:12
by linda
What is $poswords - zerkms 2012-04-04 21:14
list of positive words in a databas - linda 2012-04-04 21:15
and we need to guess it? Please replace $poswords in your regular expression with the actual value that doesn't work as expecte - zerkms 2012-04-04 21:16
@zerkms: Changing it to "that" shows the problem clearly. - Madara Uchiha 2012-04-04 21:17
@Truth: I wouldn't wonder if it is 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
why not try stristr? or other word compare functions - magicianiam 2012-04-04 21:18
$poswords is not the problem...the problem is when 'not' appears after a full sto - linda 2012-04-04 21:19
@linda: it is not how it works. If it is not a problem - just remove it from the regex, so the example become small and possible to reproduce for us, without requirement to make any assumptions - zerkms 2012-04-04 21:23
ok done edited abov - linda 2012-04-04 21:24


\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:

2012-04-04 21:21
by Andrew Leach
does mean theres no way around it - linda 2012-04-04 21:31
It simply means you have to look for exactly what you want to find. If you want to isolate 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
oh problem solved the - linda 2012-04-04 21:39