My project is a little complicated, so I'm gonna simplify with a simple example:
Let take this code:
My goal is to match and replace those tags, one by one.<ftl:loop name="c1">
<ftl:loop name="c2">
<ftl:loop name="c3">
blah
</ftl:loop>
</ftl:loop>
</ftl:loop>
But, if I want to match and replace each of those tags in the classical way (matching and replacing <ftl:loop [attributes]>(.*?)</ftl:loop>), I will never be able to parse nested tags like this, since the regex would match:
So the only way I see to match and parse those nested tags, is to start matching them from the last nested tag, which means, this one:<ftl:loop name="c1">
<ftl:loop name="c2">
<ftl:loop name="c3">
blah
</ftl:loop>
</ftl:loop>
</ftl:loop>Code: Select all
Regex used: (Matching normal and singleton tags): <ftl:loop\s+(.*?)\s*(>(.*?)</ftl:loop>|/>)
Then, Once replaced, I can run the same regex to replace <ftl:loop name="c2"> then <ftl:loop name="c1"> and my tags will have been perfectly matched.<ftl:loop name="c1">
<ftl:loop name="c2">
<ftl:loop name="c3">
blah
</ftl:loop>
</ftl:loop>
</ftl:loop>
here is my theory:
Instead of matching <ftl:loop [attributes]>(.*?)</ftl:loop> I should match <ftl:loop [attributes]>(anything except "<ftl:loop")</ftl:loop>
This way, only the last nested tag will match (<ftl:loop name="c3">), and once replaced, I can run again to match the previous tag (<ftl:loop name="c2">), then the first one (<ftl:loop name="c1">).
I tried a few things using The Regex Coach (amazing software!) but nothing works...
How can I translate in regex anything except "<ftl:loop"?
I tried (.*?)(^(<ftl:loop)*) among many other codes, but without any result.
Thank you in advance!