Navigating nested HTML tags
Posted: Fri Sep 09, 2011 1:52 pm
I've been trying to nail the problem of navigating nested XML/HTML tags and hit on the solution of entering the nesting level before and after each tag pair, working from A to Z from the innermost pair outwards, thus:
<!-- DivNest B--><div id="div1">
<!-- DivNest A--><div id="div2">
content
</div><!-- DivNest A-->
</div><!-- DivNest B-->
Having set POSIX regular expression syntax in Editor Preferences, the first job was to replace all the line feeds in the document with an unused character, such as ¬, and then replace the target tag name with another unused character, such as £, so that outer nests could be excluded from the search with a simple exception group, [^£]. Using the <div> tag as an example, I used the following Replace commands:
Find:\n
RAll:¬
Find:(</?)div([[:blank:]>¬])
RAll:\1£\2
Then it should have been just a matter of restoring the tag names enclosed in nest comments, incrementing the nest level at each iteration and finally restoring the line feeds:
Find:<£([^£]+)/£([[:blank:]¬]*>)
RAl1:<!-- DivNest A--><div\1/div\2<!-- DivNest A-->
RAl2:<!-- DivNest B--><div\1/div\2<!-- DivNest B-->
RAl3:<!-- DivNest C--><div\1/div\2<!-- DivNest C-->
RAl4:<!-- DivNest D--><div\1/div\2<!-- DivNest D-->
RAl5:<!-- DivNest E--><div\1/div\2<!-- DivNest E-->
Find:¬
RAll:\n
However, on a 91k .htm document each attempt to run the nesting replacement carried out a number of replacements interspersed with the following warning:
'Recursion too deep; the stack overflowed'
Is there a solution for this? I looked for an option to enlarge the stack in Preferences but couldn't find one.
<!-- DivNest B--><div id="div1">
<!-- DivNest A--><div id="div2">
content
</div><!-- DivNest A-->
</div><!-- DivNest B-->
Having set POSIX regular expression syntax in Editor Preferences, the first job was to replace all the line feeds in the document with an unused character, such as ¬, and then replace the target tag name with another unused character, such as £, so that outer nests could be excluded from the search with a simple exception group, [^£]. Using the <div> tag as an example, I used the following Replace commands:
Find:\n
RAll:¬
Find:(</?)div([[:blank:]>¬])
RAll:\1£\2
Then it should have been just a matter of restoring the tag names enclosed in nest comments, incrementing the nest level at each iteration and finally restoring the line feeds:
Find:<£([^£]+)/£([[:blank:]¬]*>)
RAl1:<!-- DivNest A--><div\1/div\2<!-- DivNest A-->
RAl2:<!-- DivNest B--><div\1/div\2<!-- DivNest B-->
RAl3:<!-- DivNest C--><div\1/div\2<!-- DivNest C-->
RAl4:<!-- DivNest D--><div\1/div\2<!-- DivNest D-->
RAl5:<!-- DivNest E--><div\1/div\2<!-- DivNest E-->
Find:¬
RAll:\n
However, on a 91k .htm document each attempt to run the nesting replacement carried out a number of replacements interspersed with the following warning:
'Recursion too deep; the stack overflowed'
Is there a solution for this? I looked for an option to enlarge the stack in Preferences but couldn't find one.