Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Created July 22, 2014 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbojinov/ee5a9bb7df7986a6e985 to your computer and use it in GitHub Desktop.
Save pbojinov/ee5a9bb7df7986a6e985 to your computer and use it in GitHub Desktop.
Query Parameter Parsing Using RegEx - http://www.netlobo.com/url_query_string_javascript.html
// Much faster than string splitting when you need to get a parameter
// http://jsperf.com/query-parameter-parsing
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];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment