I am trying to replace certain words in a CMS Article with the word as a Link.
This is for a website where I want to link certain words to different articles via the article id.
Here is my code so far:
let replace = ' (' + word + ') ';
html = html.replace(new RegExp(replace +'(?!(.(?!<a))*</a>)(?!(.(?!<img))*</img>)','i'), ' <span id="' + element.id+ '">' + replace + '</span> ');
Right now I get links on my words like 'example' or 'happy' or 'code' but I also want it to apply to (example) or (happy) or (code)
I tried to do a second replace like this:
let replace2 = ' \(' + word + '\) ';
html = html.replace(new RegExp(replace2 +'(?!(.(?!<a))*</a>)(?!(.(?!<img))*</img>)','i'), ' <span id="' + element.id+ '">' + replace2 + '</span> ');
but it doesn't work like this...
any Ideas? - Maybe I should use a totally different regex but so far a lot replaced the words in Image and normal links. This one works but I'm no expert...