Quote:
Originally Posted by PeterT
Why don't you give it a try? The challenge is how to match-up the correct <span> </span> pairs....
|
I'd usually search for
Code:
<span[^<>]*>([^<>]*)</span>
to get the innermost one. Once that is gone, a second pass should get rid of the outer one, shouldn't it? Unless there are other tags involved, in which case it only works some of the time.
So we'd have to use negative lookahead, as such:
Code:
(?:(?!<(?:span|/span)>).)*
to match the content inside span tags, without matching span inside span.
Final regex:
Code:
<span[^<>]*>((?:(?!<(?:span|/span)>).)*)</span>
EDIT: closing the span tag in the negative lookahead means we need to account for classes, so we will just look for and reject
which works as well, I think.
Final regex:
Code:
<span[^<>]*>((?:(?!<(?:span|/span)).)*)</span>