目前我正在使用这种模式:
/{{\s*(.+?)(\s*:\s*(.+?))?\s*}}/s
它正在做我想要的,它的匹配:
Stuff {{ something here }} blah blah {{ something : an more }} and so-forth.
我喜欢的是,如果找到另一个" {{"在模式中,例如:
Stuff {{ this will be skipped over but {{ this : will be captured }} stuff.
基本上,如果有人忘了关闭"}}"它会在击中下一个" {{"然后从那里匹配。目前在第二个例子中它匹配如下:
[0] => {{ this will be skipped over but {{ this : will be captured }}
[1] => this will be skipped over but {{ this
[2] => : will be captured
[3] => will be captured
这可能吗?
编辑:使用php的preg_replace_callback