I have a document generation application that handles tag replacement, I use a regular expression to detect said tags. These tags can be of multiple types, for the sake of the problem let's take into account the following:
I've worked with these without a problem and detected them using this RegeX expression /\{\{([^:]+)::([S|C|R|A])\}\}/g
I want to introduce nested tags at the maximum level of 1, and that's where the problem is. I've tried multiple approaches.
First approach Try it here
/\{\{([^{]+(?:\{\{[^{}]*\}\})?)::([S|C|R|A])\}\}/g
this allows me to detect only one nested tag but, as you can see the Alternative tag has problems with it.
Second approach Try it here
/\{\{(.+(?:\{\{[^{}]*\}\})?)::([S|C|R|A])\}\}/g
this detects multiple nested tags but, when a text has multiple tags it breaks.
Any help?
Found the solution: /\{\{([^{}]*(?:\{\{[^{}]*\}\}[^{}]*)*)::([SCRA])\}\}/g