简体   繁体   English

正则表达式匹配html标签之外的文本,而不是特定标签之间的文本

[英]Regular expression to match text outside html tags and not between specific tag

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...) 我试图获取一个正则表达式以匹配html标签外部和之间的某些单词(而不是标签本身),但是当它们位于html标题标签之间(h1,h2,h3等)时,我还需要排除它们

Here is what i tried: /(\\bword\\b)(?=[^>]*(<|$))/i 这是我尝试的: /(\\bword\\b)(?=[^>]*(<|$))/i

Live example: https://regex101.com/r/rM8tU3/1 实时示例: https//regex101.com/r/rM8tU3/1

Excluding heading tags is the only element missing. 缺少标题标签是唯一缺少的元素。

use this pattern to skip/ fail everything between <h1></h1> 使用此模式跳过/失败<h1></h1>之间的所有内容
Updated per comment below 根据下面的评论更新

<h1>[^<>]*<\/h1>(*SKIP)(*F)|(\bsample|text\b)(?=[^>]*(?:<|$))  

Demo 演示

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

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