I want to make my regular expression ignore if there are any tags between two characters. I thought of getting the child node list and defining some strings that corresponding start and finish tags of that nodes but I couldn't solve how to make my regular expression ignore that tags.
For example, I've listed the insert tags and made this array
let tags = ["<div class='cl'>","</div>","<span class='sp'>","</span>"]
The string in which I want to search my regular expression
let str = "The people <div class='cl'>in StackOverflow <span class='sp'> are very helpful.</span></div>"
And I want to find "people in StackOverflow" in this text to get the start and finish indexes. How can I do that?
If the regex matches both the tags and what's not in a tag.
Then you can capture and keep what's not in a tag.
/<[^>]+>|([^<>]+)/g
const str = "The people <div class='cl'>in StackOverflow <span class='sp'> are very helpful.</span></div>"
let re = /<[^>]+>|([^<>]+)/g;
let result = str.replace(re,'$1');
console.log(result);
let positions = [];
while (m = re.exec(str)) {
if(m[1]) positions.push([m.index, re.lastIndex])
}
console.log(positions);