so I got my hands on regular expressions and tried to match the outer {% tag xyz %}{% endtag %}
tags of the following text using regular expressions:
{% tag xyz %}
{% tag abc %}
{% endtag %}
{% endtag %}
My regular expression looks as follows and works so far:
({%)\s*(tag)([^%}]*?)(?:\s*(?:(%})((?:(?:[^{%]*?)|(?R))*)(?:({%)\s*(end\2)\s*(%}))))
But whenever the text inside of the matching tags contains a single {
or %
sign, the regex won't work as expected. I think it's because of the character classes that may match {%
but also {
or %
as single characters too. I tried a lot and ended up with try and error but without success.
Any help on that issue?
I setup two regex101 links for you to show the issue:
- works: https://regex101.com/r/qH0rI5/1
- does not work: https://regex101.com/r/qH0rI5/2
Any help is really appreciated!