简体   繁体   中英

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:

在此处输入图像描述

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

The following seems to work:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM