开发者

How can I write a regular expression to match lines not ending with a phrase?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜