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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.