My very first post here :) I know my way around vb and js but I'm lost with regular expressions.. Anyways I have my function below, and my problem is the function changes all words into links... even the ones inside html markups like <a href, <img, etc.
What do I need to change on the RegExp to fix that?
Thanks so much!
What do I need to change on the RegExp to fix that?
Thanks so much!
Code:
function linkWord(){
var y = document.getElementById("main").getElementsByTagName("div");
for (var i=0;i<y.length;i++){
var cname = y[i].getAttribute("class");
if (cname == "post-body") {
var x = y[i].innerHTML;
var reg = new RegExp ('\\b(' + wordlist + ')\\b','gi');
x = x.replace(reg, '<a href="/search/label/$1">$1</a>');
y[i].innerHTML = x;
}
}
}
Comment