I have a string as follows or it can be anything similar to this:
http://localhost:3003/?sp-tk=A8FEE0A4AFD2A086277CC79449AD69E5D34734455900AEED7C0A7C77EC580187D9D2FE1B286F7B5989B421B27E6FE2D1CAD2CCEB4372A80FFF6DC5D1AC6E246DB3BBAD7EB8DD7DAD1C5ED79A2114F0E3A036E898287021ABEFE642F74FAE5372E6525E0C54732B7EA9691F84C27EEB6AE60029B7613B68DA8DA3AE69887F6E815EA0A3415F08C827AF21DBFB82AE7247B297F8CFAD0DD3F7D0ED81FC095375F6242CED940B2B55D8707BCB1D85E54CBB98E83CB8
What I need is the section after sp-tk:
A8FEE0A4AFD2A086277CC79449AD69E5D34734455900AEED7C0A7C77EC580187D9D2FE1B286F7B5989B421B27E6FE2D1CAD2CCEB4372A80FFF6DC5D1AC6E246DB3BBAD7EB8DD7DAD1C5ED79A2114F0E3A036E898287021ABEFE642F74FAE5372E6525E0C54732B7EA9691F84C27EEB6AE60029B7613B68DA8DA3AE69887F6E815EA0A3415F08C827AF21DBFB82AE7247B297F8CFAD0DD3F7D0ED81FC095375F6242CED940B2B55D8707BCB1D85E54CBB98E83CB8
To do so I found a code as follows:
function getTokenFromUrl() {
name="sp-tk";
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 decodeURIComponent(results[1].replace(
/\+/g, " "));
}
and it works. But I do not understand the regular expression parts. Can anyone shed a light on that and also if there is a simpler way and maybe cleaner achieving that?