我有一个正则表达式,它匹配一个字符串并使用非贪婪语法,因此它会在第一个结束匹配处停止。我需要它在第二个结束匹配处停止。我该怎么做?
$text = "start text1 end text2 end text3 end";
$regex = "~start.+?end~";
preg_match($regex, $text, $match);
print_r($match);
Result:
start text1 end
Need Result
start text1 end text2 end
start.+?end.+?end
的正则表达式。你可能还想要边界匹配end
,这样send
、mend
等就不会被匹配到了。 - chris85