So I have a list of about 1,000 words, if they appear on the page they get replaced with something. I tried doing it with regular expressions, so for each of the thousand words I replace the content like this:
var pattern = new RegExp("(.*?)([^A-Za-z_/\-]+)("+title+")([^A-Za-z_\./\-]+)(.*?)","ig");
content = content.replace( pattern, function replacer(contents,start,before,value,after,end) {
var key = value.toLowerCase();
but this method turns out to be really slow. Another method would be to split the page content into words and then check to see if any of the parts are equal to any of the keywords. The problem there is I have a thousand keywords, so on a page with 10,000 words, I'd have to loop through 10,000 X 1,000 items which would probably crash the browser.
Does anyone know of a good way to substitute words on a page?