Welcome to WebmasterWorld Guest from 188.8.131.52
Forum Moderators: open
I'm trying to find the right Regexp string to remove empty SPAN tags
from an HTML string.
Say I have a string like so, and I want to remove the empty span tags:
<span>This is my text</span>
A simple expression like this /<SPAN>(.*)?<\/SPAN>/gi will give me the
text between the two span tags, which I can then use in a replace
This gets much more complicated when we have nested tags, however.
<span style="font-weight: bold>one <span>two <span style="color:
red">three</span> four</span> five</span>
What I really want after the replace statement is this:
<span style="font-weight: bold>one two <span style="color:
red">three</span> four five</span>
I'm having trouble crafting the perfect expression for this. I can't
seem to get my head around the right solution to handle the greedy vs
non-greedy thing, and not eliminate the wrong closing tag.
Is this even possible with straight expressions?
Thanks in advance for any help you can provide!