[Answered ]-Regex to match django block templatetag

1👍

Leaving the obvious problem of nested blocks aside, this would be the regex to match all not-nested blocks:

\{% block [^\{%]+? %\}[\s\S]*\{% endblock %\}
👤JThree

1👍

unfortunately, there is no way to use regexp here, unless you use the notation {% endblock body %}, or you don’t use nested blocks. Here is an example why it will fail:

{% block body %}
    <div class="row">
        <div class="span12">
            {% block foo %}
            [...]
            {% endblock %}
        </div>
    </div>
{% endblock %}

regex will catch nested {% endblock %} as end of the body block

👤Marat

Leave a comment