I'm writing a templating engine and I have a syntax that looks like this:
{{If "{{Line}}" != ""}}
{{If "{{Line}}" != ""}}
<li id="{{Required:Id}}" class="menuEntry line">
{{EndIf}}
<li id="{{Required:Id}}" class="menuEntry line">
{{EndIf}}
Now, I'm searching for a regex to get my if statements, meaning from {{If
until {{EndIf}}
everything in between should be included.
I came up with the regex:
/({{If)[.]*?[\s\S]*?({{EndIf}})/g
And this does work fine when I have only 1 if statement, but with nested if statements, it goes wrong.
The above regex would give me:
{{If "{{Line}}" != ""}}
{{If "{{Line}}" != ""}}
<li id="{{Required:Id}}" class="menuEntry line">
{{EndIf}}
And in fact I'm expecting to retrieve:
{{If "{{Line}}" != ""}}
<li id="{{Required:Id}}" class="menuEntry line">
{{EndIf}}
Anyone who can provide me some guidance here?