简体   繁体   中英

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...)

Here is what i tried: /(\\bword\\b)(?=[^>]*(<|$))/i

Live example: https://regex101.com/r/rM8tU3/1

Excluding heading tags is the only element missing.

use this pattern to skip/ fail everything between <h1></h1>
Updated per comment below

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

Demo

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