Skip to content

Instantly share code, notes, and snippets.

@shoveller
Created June 24, 2014 00:38
Show Gist options
  • Save shoveller/fa5fd05d8adb9f16bdbd to your computer and use it in GitHub Desktop.
Save shoveller/fa5fd05d8adb9f16bdbd to your computer and use it in GitHub Desktop.
쿼리스트링 parser
/**
* Created by cinos81 on 2014. 6. 24..
*/
var paramFromQryStr = function(url){
/*
* 첫번째 정규식
* . : 모든 글자로부터
* + : 1개 이상의 글자를
* ? : ? 를 만날 때까지
* 가져온 후, 공백으로 replace
*
* 두번째 정규식
* [^&] : &로 시작하는
* + : 1개 이상의 글자를
* /g : 여러번 취득
* */
var qryStrs = url.replace(/.+\?/,'').match(/[^&]+/g),
param = {}
for(var index=0;index<qryStrs.length;index++){
var qryStr = qryStrs[index].split('='),
key = qryStr[0]
value = qryStr[1];
param[key] = value
}
return param;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment