954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

RegExp.replace Not Working

I'm using the following function to modify tags used for mouseover text:

function delHoverX()
{
  re = /(\bdsc00001\b)/i;

  imgTags = document.getElementsByTagName("img");
  for (i=0; i<imgTags.length; i++)
  {
    if (re.test(imgTags[i].title))
    {
      origTitle = imgTags[i].title;
      origAlt = imgTags[i].alt;
      imgTags[i].title.replace(re, "$1");
      imgTags[i].alt.replace(re, "$1");
      if (origTitle == imgTags[i].title && origAlt == imgTags[i].alt)
        {
        imgTags[i].title = "same";
        imgTags[i].alt = "same";
        }
    }
    else
    {
      imgTags[i].title = "";
      imgTags[i].alt = "";
    }
  }
}


It is being used on the following web page: http://huntsvillecarscene.smugmug.com/gallery/1144571

For some reason, the regexp.replace is not working. There is a test clause in there to help me diagnose some of what's going on.

I'm not a Javascript programmer. I only have a limited background in C. I've been working on this for 2 days and am frustrated out of my mind.

Any assistance appreciated.

Samir
Newbie Poster
20 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

Anyone?

Samir
Newbie Poster
20 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

Regular Expressions have always been very difficult for me, for some reason. I'd be happy to try to help when I have a bit more time later this week.

Can you post a very simple "test harness" version of your HTML here?

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

it should be \i not /i for case insensitive in your re (first line of code) so you are possibly never getting a match. its is easy to miss as some others are / (for example /g for whole string)

f1 fan
Posting Whiz in Training
279 posts since Jan 2006
Reputation Points: 26
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You