捕獲cookie的值

王東煜發表於2019-09-27
function getCookie(){
    var reg = /([^ ;=]+)=([^ ;=]+)/g;
    var ary = reg.exec(document.cookie);
    let obj = {};
    ary.forEach(a => {
        obj[a[1]] = a[2]
    });
    return obj;
}
console.log(getCookie());

//捕獲字串中標籤的ID 和 文字
var str = '<div id="container" class="main"> hello world </div>';
var reg = /id=['"](\w+)['"]/
reg.exec(str)
var reg = />([^><]+)</;
reg.exec.(str)
複製程式碼

相關文章