I have HTML text and I have a specific phrase. I need to find my phrase inside HTML text and highlight it, but I have to skip my phrase if it's inside h or a tags
For Example: Here is my phrase: "phrase to highlight"
This is my HTML Text
<p>Here starts text and here is phrase to highlight</p>
<a>here, phrase to highlight, supposed to be skipped</a>
<h3>here, phrase to highlight, supposed to be skipped</h3>
<div class="phrase to highlight">Here phrase to highlight must be highlighted again</div>
p and div tags should highlight my phrase, a and any h tags should skip my phrase.
I do negative lookbehinds to find my phrase and make sure it's not an HTML attribute
var Pattern = $"(?i)(?<!</?[^>]*|&[^;]*)(\bphrase to highlight\b)";
How can I modify my regex to exclude a and h tags?