Do it in two steps:
1 - get everything in between struc and end struc
2 - for every match in step 1, find all elem's
The requirement is that it had to be in one expression. I realize that the problem could be easily solved if the special program was created.
And if your struc/end struc's are nested, then regex is not the right tool for the job. You need a true recursive descent parser. In which case, Google is your friend.
I agree - nesting can't be expressed in reg exps. And you are right - the alternative solution was the parser.
Btw, this looks like the same thing as in your other thread. Perhaps it's better to keep the discussion in one thread?
The problem is exactly the same, but i wanted to approach it from two different views (the most intuitive). Later i will join them though.
"Variable length look behinds" are not supported by PHP's preg-methods.
I am using PowerGrep for this
elem\s\S+(?=(?:(?!struc).)*end\sstruc)
And now i am lost. It is exactly what you suggested me some time ago, but then i couldn't make it working. But now - it is. And the hack you used - it works even for nested elements.
But to be sure - you check if elem is followed by end-struc which is not preceded by struc (the hack)?
AND:
does anyone knows why neither of the
or
works? Neither in Perl or PowerGrep...
Thanks!