By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

How do I tell regexp to exclude html tags?

P: 1
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!

Expand|Select|Wrap|Line Numbers
  1. function linkWord(){
  2.   var y = document.getElementById("main").getElementsByTagName("div");
  3.   for (var i=0;i<y.length;i++){
  4.     var cname = y[i].getAttribute("class");
  5.     if (cname == "post-body") { 
  6.       var x = y[i].innerHTML;
  7.       var reg = new RegExp ('\\b(' + wordlist + ')\\b','gi');
  8.       x = x.replace(reg, '<a href="/search/label/$1">$1</a>');
  9.       y[i].innerHTML = x;
  10.     }
  11.   }
  12. }
Aug 6 '09 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 5,390
hmmm ... perhaps you could tell with plain text what you want to replace in the innerHTML of the divs? just for me ... so that i might understand the requirement a bit better :)

kind regards
Aug 7 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.