Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串说 $str - This is my test string that needs to be matched and not the test keywords following it
This is my test string that needs to be matched and not the test keywords following it
输出-This is my test
This is my test
但我的正则表达式模式: (.*?)test
匹配到最后。请帮助如何实现相同的目标
您可以使用这个简单的正则表达式:
^.*?test
或者最好不要使用正则表达式并使用strpos字符串函数。
strpos
$pos = strrpos($str, "test", 0); if ($pos === true) { // found... }