I am currently working on a simple template engine. In a template, if-statements can be used. An if block looks like this
{% name IF: a EQUALS b %}
content
{% name ENDIF %}
I want to identify these blocks via regex. The Problem is I need a regex pattern which contains two unknown but equal parts. This is the pattern which matches to all blocks:
/{% +(.*) +IF: +(.*) +%}([\s\S]*){% +(.*) +ENDIF +%}/gm
To clarify which ENDIF marker belongs to which IF the first and the last capture group needs to be the same. Is there a way to do this?