Regex to minimize the repeated

tags to one

tag

regex

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

Best Solution

 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

Related Question