pc_oc
pc_oc

Reputation: 545

Regex to remove empty tags HTML except images

I have a regex to remove empty tags HTML, like <p></p> or <span></span>, but inside them I can have images and I want to ignore the tag <img>. My regex:

(<(?!\/)[^>]+>)+(<\/[^>]+>)+

My uses cases:

enter image description here

I want to ignore the last line, because I have an image inside the tag.

Check the live editor: https://regex101.com/r/81M8VR/1

Upvotes: 0

Views: 370

Answers (1)

von_court
von_court

Reputation: 302

The following seems to work:

(<(?!\/)((?!img)[^>])+>)+(<\/[^>]+>)+

https://regex101.com/r/A0N1rL/1

Upvotes: 1

Related Questions