If i write the next line alone he cut's it for no reason, so...:
Hello,
i need help for this, i'm out of my knowledge.
i'm stuck at a small TPL-System which should do some foreach and if statements. I do this in PHP but idk if this relevant.
https://regexr.com/62ho9 here you can see my issue. I want that the regex end by the second {/if} but it does not. Is there any possible solution to do this with regex?
If not, do you maybe have a good idea for PHP to do what i want? Because i'm out off ideas.
(?<={if \!TEST})([\s\S]*?)(?={\/if})
<a class="dropdown-item" href="#">
{if !TEST}
{USERNAME}
{if !TEST}
HI
{/if}
klöaksdölsa
{/if}
asdas
{if !TEST}asd{/if}
</a>
At the moment i use {if ID statement} LOREM {/if ID} but the more elegant solution would be without an ID :D
(TEST: Hi guys) <-- because he cuts it every time from the start?!
Yes, you can use recursion in PHP regex and the regex you could use is
(?s){if\s+!TEST}((?:(?!{(?:if\s+!TEST|\/if)}).|(?R))*){\/if}
See the regex demo. You just need to get the Group 1 value after you get a match.
Details:
(?s) - an s inline flag{if\s+!TEST} - {if, one or more whitespaces, !TEST}((?:(?!{(?:if\s+!TEST|\/if)}).|(?R))*) - Group 1: zero or more occurrences of
(?!{(?:if\s+!TEST|\/if)}). - any char that is not the starting point of a {if !TEST} and {/if} char sequences|(?R) - the whole pattern recursed{\/if} - an {/if} substring.