比如:要截取网址中的键值
function getUrlStr(name, str) {
const reg = new RegExp((^|&)${ name}=([^&]*)(&|$)
);
const r = str.substr(1).match(reg);
if (r != null) return decodeURIComponent(r[2]); return null;
}
let arr = "https://www.baidBB&rsv_idx=2&tn=baiduhome_pg&unioid=123456&ie=utf-8&rsv_cq=js%80&rsv_dl=0_right__01/&rsf=e2b5e820bb29bef0&abc=c2a1418d76b6ec59_1_15_14&rqid=a938d8c200010bf9"
let aaa = getUrlStr("ref",arr)
console.log(aaa,"aaa")
//控制台打印的值为 e2b5e820bb29bef0