Pre-scriptum: I'm purely curious, and am aware of other perfectly suitable solutions to this, that lie outside the domain of regular expressions.
How do I match from a beginning tag, and until a closing tag with possible nested, and perhaps identical tags. So say I have given in an HTML file:
<div class="nice">
<a href="http://www.google.com">Hello</a>
<div>World</div>
</div>
Let's say I want to comment that out via regex replace. One could do a simple
/(<div\sclass=\"nice\">(.*)</div>)/
But that would of course match until the VERY LAST closing div tag, rendering the code foul if the nice div is embedded inside another div. Making the delimiter non-greedy would render the code foul even more, matching until the VERY FIRST closing div tag.
So any ideas? I've often thought about this, and I've never found a solution, is this impossible in regex, or is it just me that's forgetting something simple? Isn't there some sort of "look-back" mechanism?