Help with Javascript RegExp

mpmcleodmpmcleod Registered Users Posts: 288 Major grins
I am having some problems with making RegExp work in both FF and IE. Specifically it has to do with the /.

In FF the following works fine:

replaceText = new RegExp(">save photo</a>\\s*\\|");
if ( replaceText.test(document.body.innerHTML) == true) {

}

but it doesn't work in IE nor in Opera.

I have tried escaping the / by using 1,2 and 3 \ but none works.

What I am trying to do is shown here:
http://mpmcleod.smugmug.com/gallery/1470992

Currently I have a second routine that is called which checks '>save photo<' and replaces just that text for IE and Opera.

thanks for any help or ideas.
-- Mike

smugmug nickname: mpmcleod
http://www.michaelmcleod.com/

Comments

  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited June 8, 2006
    Hi Mike,

    Sorry it's early here....i will look when I get to work and have had some coffee.

    Cheers,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • devbobodevbobo Registered Users, Retired Mod Posts: 4,339 SmugMug Employee
    edited June 8, 2006
    ok, i think the problem is that you're not escaping the /

    replaceText = new RegExp(">save photo<\\/a>\\s*\\|");

    Personally, I don't like this RegExp syntax since u need to use double \.

    The alternative way is...

    replaceText = />save photo<\/a>\s*\|/

    Hope this helps,

    David
    David Parry
    SmugMug API Developer
    My Photos
  • mpmcleodmpmcleod Registered Users Posts: 288 Major grins
    edited June 8, 2006
    devbobo wrote:
    ok, i think the problem is that you're not escaping the /

    replaceText = new RegExp(">save photo<\\/a>\\s*\\|");

    Personally, I don't like this RegExp syntax since u need to use double \.

    The alternative way is...

    replaceText = />save photo<\/a>\s*\|/

    Hope this helps,

    David
    Found the problem still don't understand it. <img src="https://us.v-cdn.net/6029383/emoji/headscratch.gif&quot; border="0" alt="" >
    IE/ Opera both REQUIRE the /i flag even though the match is lowercase.
    while FF is smart enough to know it is not needed.
    replaceText = new RegExp(">save photo</a>\\s*\\|","i");
    or
    replaceText = />save photo<\/a>\s*\|/i;
    
    works in both while leaving off the ignore case flag breaks it in IE/Opera....

    Thanks for the help.

    Edit: The first part of the code is wrong. Dgrin keeps editing it and removing the a tag. Even wrapped with code tags the tag still gets removed.
    -- Mike

    smugmug nickname: mpmcleod
    http://www.michaelmcleod.com/
Sign In or Register to comment.