...

View Full Version : Search, Replace and Back Reference



Tobai
10-02-2008, 05:09 PM
I'm trying to modify a page's url tags. For some reason, I can't get it to reference digits.

Here's an original url: http://www.example.com/browse.php?page=1234
I'm tring to modify to: http://www.example.com/browse/page/1234/fix

This is what I'm using.


var links = document.getElementsByTagName('a');
for (i = 0; i < links.length; i++) {
links[i].href = links[i].href.replace('\/browse\.php\?page=', '\/browse\/page\/');
}


Above works but I can't append '/fix' to the end of that line. Normally, I would backreference

\/browse\.php\?page=(\d+)', '\/browse\/page\/\1\/fix'

But I can't capture those digits. Am I'm not escaping something? Should be simple.

Even if I just use '\/browse\.php\?page=\d+', it won't match the above url?

oesxyl
10-03-2008, 05:12 AM
var links = document.getElementsByTagName('a');
for (i = 0; i < links.length; i++) {
var s = links[i].search;
var l = links[i].href;
links[i].href = l.replace(/\.php/,'/page/' + s.replace(/\?page=(\d+)/,'$1'));
links[i].search = '';
}


regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum