0
組
我想匹配:之間 一切 「{{環(東西)}}」 和第{{/環路(的東西)}}回用正則表達式匹配
文本例如:
{{ 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;
撲通!謝謝,@DaveRandom,但我已經在發表評論時糾正了它。正在考慮PHP的Perl instad。 –
酷,這可能是答案然後:-) – DaveRandom
Yeeeeeep !!!!!謝謝,我準備好了;) –