javascript – Regex – match text not inside HTML a-tag

I’m trying to create a regex that matches “Wonder woman” as long as it is not inside an a-tag.

The regex I have so far:

(Wonder woman)?<a.*?</a>|({S+?})

This matches the a-tag from beginning to end (including both). I think I’m close, but I’m out of ideas.

In the following string, I want to match the word “wonder woman” (case insensitive) as long as it is not insinde an a-tag. It’s the last two lines (seperated by a new-line) that I’m trying to create a regex for.

Don't match me. I'm just random text <a>Wonder woman</a>
<a> Wonder
Woman test test 
This is some random text that  should not be matched. 

I also tried the following regex but it doesn’t match “wonder woman” if it’s on two seperate lines:

wonder woman(?![^<a>]*?</a>)

Any help with my regex is much appreciated.

Note: I’m not interested in replacing everything else with an emtpy string.

I want to match the specific word(s) and then insert a different word, let’s say “Captain America”.

Read more here: Source link