正则表达式提取url中的参数,返回json字符串

var urlstr = "www.baidu.com?a=1&b=xx&c";
var s = urlstr.split("?");
var argstr="";
console.log(s);
if(s.length>1){
    argstr = s[1];
}
var parttern = /([a-z]+)(=)?([a-z0-9]*)/gi;

var matches = parttern.exec(argstr);
var arraymatches = [];
while(matches){
    arraymatches.push(matches);
    matches = parttern.exec(argstr);
}
console.log(arraymatches);
var jsonop = {};
for(var i=0;i<arraymatches.length;i++){
    var temp = arraymatches[i];
    jsonop[temp[1]] = temp[3];
}
console.log(jsonop);
console.log( JSON.stringify(jsonop));
上一篇:cf--2A


下一篇:通过Maven插件发布JaveEE项目到tomcat下