views:

43

answers:

1

I have this piece of text in a string:

<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center; line-height: normal;" align="center"><i style=""><span style="" lang="ES-TRAD">some text
another text<o:p></o:p></span></i></p>

<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: center; line-height: normal;" align="center"><i style=""><span style="" lang="ES-TRAD">some text more
and some text more<o:p></o:p></span></i></p>

If I do

string.replace(/[\r\n]/g, "");

all carriage returns will be removed, I just want to remove those who are between "some text" and "another text", I mean inside the spans.

Thanks in advance.

+1  A: 
/[\r\n]+(?=(?:(?!<span\b)[\s\S])*<\/span>)/i

That will match newlines that are inside <span> elements. It will also match inside the opening <span> tag, as well as in any other tag that's contained in a <span> element. That probably doesn't matter, but I'm in a full-disclosure kind of mood. ;)

Alan Moore
It's working, thanks a lot Alan!
santiagokci