【发布时间】:2016-10-15 16:50:15
【问题描述】:
我正在构建一个模板引擎,并希望允许嵌套逻辑。
我需要使用“@”作为分隔符来拆分以下字符串,但我想忽略这个分隔符 - 将其视为另一个字符 - 如果它在 [方括号] 内。
这是输入字符串:
@if(param1>=7) [ something here @if(param1>9)[ nested statement ] ] @elseif(param2==true) [ 2st condition true ] @else [ default condition ]
结果应该是这样的:
array(
" if(param1>=7) [ something here @if(param1>9)[ nested statement ] ] ",
" elseif(param2==true) [ 2st condition true ] ",
" else [ default condition ] "
)
我相信 preg_split 是我正在寻找的,但可以使用正则表达式的帮助
【问题讨论】:
-
不试就出问题了?
-
尝试了以下模式无济于事:/@+(?![^[@]]*])/x
标签: php regex templates preg-split