Created
July 22, 2014 00:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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