js正则表达式获取url参数

let reg =/([^?&+#]+)=([^?&+#]+)/g;
let obj={};
let href = 'http://www.runoob.com/jquery/misc-trim.html?channelid=12333&name=xiaoming&age=23';
href.replace(reg,($0,$1,$2)=>obj[$1]=$2)
console.log(obj);

 

转载于:https://www.cnblogs.com/huang-gua/p/10063097.html

你可能感兴趣的:(js正则表达式获取url参数)