删除回车用正则表达式

问题描述:

我有这样的一段文字中的字符串:删除回车用正则表达式

<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> 

如果我做

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

所有回车将被删除,我只是想删除那些介于“某些文本”和“另一文本”之间的人,我的意思是在这些跨度内。

在此先感谢。

+5

你知道[你不能用正则表达式解析HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/ 1732454#1732454),对吧? – 2010-08-11 04:12:11

+0

但是,当然,您可以使用不规则表达式解析HTML! – 2010-08-11 04:15:34

+0

@Daniel Pryden:不,不过谢谢。 – santiagokci 2010-08-11 04:22:58

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

这将匹配<span>元素内的换行符。它也将匹配<span>标签以及包含在<span>元素中的任何其他标签。这可能没有关系,但我处于一种充分披露的情绪。 ;)

+1

它的工作,非常感谢艾伦! – santiagokci 2010-08-11 14:19:41