I have to select rows that contain the word one and not another. The rows come form some json string, like those:
{"Name" : "one", "LastError" : "No error", "ID" : 1000 , "Comment" : "no comment"} //YES
{"Name" : "one", "LastError" : "No error", "ID" : 1000 , "Comment" : "another"} //NO because there is 'one' and 'another'
I am using php and preg_match.
I’am trying to use someting like:
if (preg_match('/one.*(?!another)/i',$row_string) > 0)
{
//no draw
}
else
{
//Draw something
}
It seems that the look ahead doesn’t do anything.
Your regex
means match the string
onefollowed by any number of characters, and the string after.*must not matchanother..*will basically match up to the end of the string, so it isn’t followed byanother.What you actually want is to match the string
onefollowed by any number of characters, and each of them must not be followed byanother.This one works:
The
$makes sure that the assertion is tested against every character followingone.To make sure that even
oneitself isn’t preceded byanother, we have to add the assertion just afteronetoo: