Skip to content

Instantly share code, notes, and snippets.

@kanakiyajay
Created May 26, 2014 08:37
Show Gist options
  • Save kanakiyajay/5ee6776b8015770744ab to your computer and use it in GitHub Desktop.
Save kanakiyajay/5ee6776b8015770744ab to your computer and use it in GitHub Desktop.
Get only one value from the query string value using Regex and javascript
function getQueryMatch (query,key) {
var regx = new RegExp(key+"=([^&]*)");
return decodeURIComponent(query.match(regx)[1]);
}
console.log(getQueryMatch("http://example.com?x=hello&y=des%20t","y"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment