I built a regex in PHP that will match an entire HTML element with a class of 'myClass'. It's probably not perfect, but it works pretty well thus far. The preg_match it's being used in looks like this:
preg_match_all('/<([A-Z][A-Z0-9]+) .* class *= *"myClass".*>(.*)<\/(?R)>/im', $file, $matches);
This matches:
<div class="myClass">...[anything inside EXCEPT another div element]...</div>
However, using a <div> as an example, this will not match the entire element if another <div></div> is nested inside.
I read somewhere that the .NET regex evaluator supports depth constructs so you can do something like this:
<div> (?><div (?<DEPTH>) | </div (?<-DEPTH>) | .? )* (?(DEPTH)(?!))</div>
...which will match the part in red below:
[FONT="Courier New"]<div>this is some <div>red</div>text</div></div></div>[/FONT]
Any regex experts have a trick up their sleeves for something like this in PHP?