>我有一个字符串说$str - This is my test string that needs to be matched and not the test keywords following it
输出 - This is my test
但是我的正则表达式模式:(.*?测试
匹配到最后。请帮助如何实现相同的目标
您可以使用这个简单的正则表达式:
^.*?test
或者最好不要使用正则表达式并使用strpos
字符串函数。
$pos = strrpos($str, "test", 0);
if ($pos === true) {
// found...
}