I have searched stack overflow for a Javascript solution (in the jQuery library) to get the URL parameter.
I have this function which does it smoothly:
// get the firstname value from the myurl - http://mysite.com?firstname=dany&lastname=dughy
var myurl = $("#gup").data("url");
var name = "firstname";
function gup(name, myurl) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec(myurl);
if( results == null )
return "";
else
return results[1];
}
I understand how it works, you set a regex and than execute that regex and retrieve the results in an array.
Can someome please explain the regex to me? I can't seem to understand it.
Ty