Discussions
Probably easy regular expression question
I’ve seen this code before on the forum and it works great. Pass it the parameter in the URL that you are looking for and it returns the value.
var partnerValue = gup('partner');
/***********************************
Get URL Parameter
***********************************/
function gup(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return results[1];
}
Using the above, if I have www.mysite.com/index.html?partner=0104-The Cool Store
It would return “0104-The Cool Store”.
However, I want to further parse out what is returned, either in the gup function or by calling another function afterwards. Basically, I want be able to have two values in the end: