使用正则表达式解析http请求url中的参数和参数值

<html>
<script>
var test = "#token=Be&access_token=fff&$id_token=ets&expires_in=3600&scope=full";

var anotherTry = function(value) { 
    var reg = /(?:^\#|&)(.*?)=(.*?)(?=&|$)/g; // 字符串结尾
    var temp;
    while((temp = reg.exec(value))!= null) {
    	console.log("Key: " + temp[1] + " value: " + temp[2]);
    }
};

anotherTry(test);
debugger;
</script>
</html>
发布了7153 篇原创文章 · 获赞 654 · 访问量 122万+

猜你喜欢

转载自blog.csdn.net/i042416/article/details/104950933
今日推荐