I'm trying to match any bracketed items within <sup>
tags.
My regular expression is being too greedy, starting with the first <sup>
tag and ending at the last </sup>
tag.
/<sup\b[^>]*>(.*?)\[(.*?)\](.*?)<\/sup>/
Example html:
<sup>[this should be gone]</sup>
<sup>but this should stay</sup>
<sup>this should [ also stay</sup>
[and this as well]
<sup><a href="#">[but this should definitely go]</a></sup>
Any idea why?
Thanks!
EDIT: I suppose these answers make sense. I've got much of the HTML parsed without regex; I just figured that this particular example would work with regex because it would do the following:
- see the first
<sup>
tag - find the first instance of
</sup>
- search the inside for (wild)(bracket)(wild)(closing bracket)(wild)