匹配一个字符串后面跟着另一个字符串(preg_match负向前看)

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

/one.*(?!another)/

means match the string one followed by any number of characters, and the string after .* must not match another.

.* will basically match up to the end of the string, so it isn't followed by another.

What you actually want is to match the string one followed by any number of characters, and each of them must not be followed by another.

This one works:

/one(.(?!another))*$/

The $ makes sure that the assertion is tested against every character following one.

To make sure that even one itself isn't preceded by another, we have to add the assertion just after one too:

/one(?!another)(.(?!another))*$/

one is only in Name? If so, json_decode($json, true).