使用正則表達式解析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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章