我正在尝试匹配:“{{ loop (something) }}”和第一个 {{ /loop (that something) }} 之间的所有内容
文本示例:
{{ LOOP data }}
<span> Member key = {{.key}} </span>
<span> Member value = {{.}} </span>
<span> Member member = {{name}} </span>
<span> Iteration number = {{.counter}} </span>
{{ /LOOP data }}
这是正则表达式不起作用:
/\{\{\s+loop\s+(.+?)\s+\}\}([\w\W]+?)\{\{\s+\/loop\s$1\s+\}\}/i
如您所见,我正在尝试使用“$1”重用第一个匹配的组:我错过了什么?
php代码如下:
$text = '
{{ LOOP data }}
<span> Member key = {{.key}} </span>
<span> Member value = {{.}} </span>
<span> Member member = {{name}} </span>
<span> Iteration number = {{.counter}} </span>
{{ /LOOP data }}
';
preg_match('/\{\{\s+loop\s+(.+?)\s+\}\}([\w\W]+?)\{\{\s+\/loop\s\1\s+\}\}/i', $text, $match);
print_r($match);
die;