I have a long string which basically contains the whole HTML code of a page.
There are links in this page and I need to add a set of parameters at the end of these links.
Nb : All href are the same in the all page.
I managed to extract the URL in a variable with this code (html var contains my html code) :
var href = html.match(/href="([^"]*)/)[1];
Adding extra parameters :
var newHref = href+'&n=$ln$&p=$fn$&e=$e$';
I escape the first href with this function for regexp purpose :
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|\=\%\:\&]/g,"\\$&");
}
Then I try to perform the replacement in the code :
var reCompletion = new RegExp(escapeRegExp(href),"g");
html.replace(reCompletion, newHref);
When I run this code it cannot find any match with the URL and perform no replacement at all.
Here is the kind of URL I have to complete :
http://action.mySite.com/trk.php?mclic=P4CAB9542D7F151&urlrv=http%3A%2F%2Fjeu-centerparcs.com%2F%23%21%2F%3Fidfrom%3D8&urlv=517b975385e89dfb8b9689e6c2b4b93d
Once escaped :
http\:\/\/action\.mySite\.com\/trk\.php\?mclic\=P4CAB9542D7F151\&urlrv\=http\%3A\%2F\%2Fjeu\-centerparcs\.com\%2F\%23\%21\%2F\%3Fidfrom\%3D8\&urlv\=517b975385e89dfb8b9689e6c2b4b93d
Does anyone have any clue about this ?