Reputation: 33
I'm using my own PHP code to render template files as HTML codes. I need a regex to parse the recursive tags correctly, in this example it's the permission tags.
Example: Template code:
<if condition="is_admin">
Show this
<if condition="can_do_this">
Show this
</if>
<if condition="can_do_that">
Show that
</if>
</if>
I want to capture the contents inside each 'if' tag correctly, and of course without any nested tags problems.
I saw a Regex that will work perfectly on css:
/{(?:[^{}]+|(?R))*}/sg
However when I change to my format, it's not working. I've changed to:
/<if condition="(.[^"]*)">(?:(?!<if condition=".[^>]*">|<\/if>)|(?R))*<\/if>/sg
What should I change for it to work?
Thank you.
Upvotes: 1
Views: 127