Created
June 24, 2014 00:38
-
-
Save shoveller/fa5fd05d8adb9f16bdbd to your computer and use it in GitHub Desktop.
쿼리스트링 parser
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
/** | |
* 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