开发者

Problem with or in Regexp

I have this Regexp:

/\{%\s([^else|endloop|endif][a-z0-9\.\|_]+)\s%\}/si

I use this regexp in preg_replace. And this markup:

{# comment %}

{# comment number 2$% %}

{% variable %}

{% array.key1.key2 %}

{% array.key1.key2|esca开发者_开发百科pe|bold %}

{% variable|escape %}

{% loop array as item %}
    My item is {% item.text %}
{% endloop %}

{% if (something): %}
    do something truly
{% else: %}
    nothing to do
{% endif; %}

Why this regexp is not working for {% item.text %} but works with other? I think that I made some mistake here [^else|endloop|endif]

What I'm doing wrong?


I think you may intend:

/\{%\s((?!(else|endloop|endif))[a-z0-9\.\|_]+)\s%\}/si

The square brackets previously containing the else, endloop and endif keywords treats each individual character as an exception. Here they are treated as whole strings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜