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.
精彩评论