$string = "start start content end";
像preg_match这样:
preg_match('/start(.*?)end/', $string, $matches);
echo $match[1];
但是,问题是$matches [1]返回开始内容不仅仅是内容,因为$string中有两个开头(也许更多)
解决方法:
使用否定前瞻:
$string = "start start content end";
preg_match('/start\h*((?:(?!start).)*)end/', $string, $matches);
echo $matches[1];
// content
(?:(?!start).)将匹配任何字符,如果没有后跟start.