我有 2 个段落,带有 html 标签<p class="mb-40px"></p>
在这个标签里面有文本和另一个 <p..> 标签
我需要找到并删除包含在主标签中的 html 标签<p class="mb-40px"></p>
例子:
<p class="mb-40px">Miracles every day <p lang="ro-RO" align="JUSTIFY">being at la home, the poet Petru Iliesu made an international appeal to condemn the killing of demonstrators, shot on the streets of town.</p>
<p class="mb-40px">The pleasure we feel after reading a book is different from the pleasure of tasting a dish <p class="dis23">. In the first case, pleasure is disinterested, having no particular purpose, as a release from external preoccupations.</p>
输出
<p class="mb-40px">Miracles every day being at la home, the poet Petru Iliesu made an international appeal to condemn the killing of demonstrators, shot on the streets of town.</p>
<p class="mb-40px">The pleasure we feel after reading a book is different from the pleasure of tasting a dish. In the first case, pleasure is disinterested, having no particular purpose, as a release from external preoccupations.</p>
我的正则表达式不太好:
寻找: (?:<p class="mb-40px">|\G)\S*\K(?:\h+<\s*(\w+)[^/>]*>)(?=.*</p>)
替换为:(留空)
这是您修改后的公式,适用于我:
<p class="mb-40px">.*\K(?:\h+<\s*(\w+)[^\/>]*>)(?=.*<\/p>)
?:<
,\G
如果你仍然使用\K
\S*
仅当您只有一个单词且标签之间没有空格时才有效,请.*
改用/
需要转义:\/
这是一个更短的表达式:
<p class="mb-40px">.*\K<p[^>]+>
是的,我自己设法找到解决方案:
寻找:
(?-i:<p class="mb-40px">|\G(?!^))(?s:(?!</p>).)*?\K(?-i:<\s*(\w+)[^/>]*>)
替换为:
LEAVE EMPTY
所以,如果我想查找/替换其他两个部分中的内容,通用正则表达式将是:
(?-i:REGION-START|\G(?!^))(?s:(REGION-FINAL).)*?\K(?-i:FIND REGEX)