Given this text :
[start block1]
[end block1]
lorem
[start block2]
ipsum
[start block2_1]
[end block2_1]
dolor
[end block2]
Is it possible with a regex to match block1 & block2 without block2_1.
Of course we cannot rely on the name of the block but only that fact that he is nested in another block.
Try this:
As long as you aren’t repeating any block name, you should be fine.
\1will match the name of the block you’ve started, and capture anything inside. Make sure to use the dot-all option (or single-line),/s, or the[\s\S]*hack if your flavor doesn’t support it (like JavaScript).In PHP, use this code:
You can then easily get the names:
Working example: http://ideone.com/OsbSt