正则表达式匹配html标签之外的文本,而不是特定标签之间的文本 [英] Regular expression to match text outside html tags and not between specific tag
本文介绍了正则表达式匹配html标签之外的文本,而不是特定标签之间的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图获取一个正则表达式以匹配html标记外部和之间的某些单词(而不是标记本身),但是当它们位于html标题标记(h1,h2,h3等)之间时,我还需要排除它们...)
I trying to get a regular expression to match some words outside and between html tags (and not in tags themselves), but I also need to exclude them when they are between html heading tags (h1, h2, h3, etc...)
这是我尝试的方法:/(\ bword \ b)(?= [^>] *(< | $))/i
实时示例: https://regex101.com/r/rM8tU3/1
唯一的缺少元素就是标题标签.
Excluding heading tags is the only element missing.
推荐答案
使用此模式跳过/失败< h1></h1>
之间的所有内容在下面的每个评论中更新
use this pattern to skip/ fail everything between <h1></h1>
Updated per comment below
<h1>[^<>]*<\/h1>(*SKIP)(*F)|(\bsample|text\b)(?=[^>]*(?:<|$))
这篇关于正则表达式匹配html标签之外的文本,而不是特定标签之间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文