I need a PHP regular expression that matches a line beginning, but not ending, with a phrase. Something like:
$s = 'top bus stop';
$b = preg_match('/^top.*(?!top)$/', $s);开发者_如何转开发
But one that actually works. What do you think?
You had it almost right. But the final assertion should be (?<!top)
a lookbehind assertion using a <
prefix. This way it really looks at the preceding three characters before the $
subject end.
精彩评论