Hello,
I would like to wrap (surround) all words "flyer" (case insensitive) in the HTML text content, not those in the link. My RegEx works fine on Regex101: https://regex101.com/r/NVmXd1/1
Attached, my HTML file to test my (non working) JS RegEx.
Thank you and regards.

I found a solution to my problem. See attached HTML file.
Solution:

function testRX() {
    var rex=new RegExp("(?<=>[^<]*)(flyer)|(flyer)(?=[^>]*<)","gi"); //Previous one had mistake
    var str=document.getElementById("str").textContent; //Not .innerHTML
    var res=str.replace(rex,"<u>$1$2</u>");
    document.getElementById("res").textContent=res;
}

I'm glad you got it working. Sorry, I just saw this thread now. I, myself, struggle quite frequently with Regex. Regex101 is always my lifesaver. Thank you so much for posting your solution so that it can be helpful to others in the future.

I've marked this question solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.