开发者

Regex to minimize the repeated <p></p> tags to one <p></p> tag

Through the code i got the output content as XML. I have pair or multiple of XML tags as follows:

<p>December10</p>
<p>
</p>
&开发者_开发知识库lt;p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p> Welcome to this space </p>
<p>
</p>
<p>
</p>
<p>Hai, Today is Tuesday</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>This a xml tag</p>

I want a regular expression as below requirement:

As above mentioned i want only one EMPTY pair Tag as <p></p>. I do not want the repeated EMPTY indefinite or definite pair tags.

Please help me in this regard to use regular expression to overcome the issue.


 s/(<p><\/p>)+/<p><\/p>/g;

this one work for me (meaning == I tested it with your tagsoup).. it is perl/sed syntax, s///g means 's' replace and 'g' global


Oh God, please don't let bobince see you asking this question.

See: RegEx match open tags except XHTML self-contained tags or Parsing Html The Cthulhu Way


If this is .NET, you could try something like this:

Regex.Replace(content, "(<p>\s*</p>\s*?)+","<p></p>")

Or even better

Regex.Replace(content, "(<p>\s*</p>\s*?)+","<p/>")

(Edited to add Gumbo's suggestion)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜