Some JavaScript + REGEX goo to get query strings from your HREF/URI/URL

I guess there is a library somewhere to do this, but I couldn’t find it fast enough so I spit this contraption out. It’s a function that grabs the value from a URI/URL query string. Yes, writing those nasty REGEXs about drove me nuts! 😉 Maybe I can save at least one soul out there some trouble. If you see an enhancement option or have ideas, please comment and let me know!

[sourcecode language=”javascript”]
function GiveMeTheQueryStringParameterValue(parameterName) {
parameterName = parameterName.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + parameterName + "=([^&#]*)");
var results = regex.exec(window.location.href);
if (results == null)
return "";
return decodeURIComponent(results[1].replace(/\+/g, " "));