简体   繁体   English

正则表达式删除空标签 HTML 除了图像

[英]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> .我有一个正则表达式来删除空标签 HTML,如<p></p><span></span> ,但在它们里面我可以有图像,我想忽略标签<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查看实时编辑器: https://regex101.com/r/81M8VR/1

The following seems to work:以下似乎有效:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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