We're currently implementing a little tag system into our software. There are just two different tag styles: single ones and multiple ones.
The single ones look like this:
<<Single_Tag>>
The multiple ones look like this:
<<Multiple_Tag*>>
... stuff between tag ...
<</Multiple_Tag*>>
The RegEx to find the single ones would be:
<<\w+>>
The RegEx to find the multiple ones would be:
<<(\w+)\*{1}>>((.|\s)*)<</(\w+)\*{1}>>
Are the {1}
's required? Am I right, that (.|\s)*
needs to be greedy? Otherwise this RegEx would fail on:
<<multiple_tag1*>>
<<multiple_tag2*>>
<</multiple_tag2*>>
<</multiple_tag1>>
Is there maybe an easier way with capturing groups? Excuse me, if the following syntax is wrong. The last time I've used RegEx is years ago:
<<(\w+)\*{1}>>((.|\s)*)<</($1)\*{1}>>
That $1
stands for the first capturing group. I'm developing in .NET. I checked these on RegExr, already. But I just remember: it's very easy to overlook something while working with RegEx.