怎样用正则替换掉url某个参数

2024-12-27 08:31:03
推荐回答(1个)
回答1:

var url="http://localhost/index.jsp?a=123&b=as";
//url.replace(/(?![?&])(参数名)=\w+/gi,"替换后的参数");
url=url.replace(/(?![?&])(b)=\w+/gi,"c=456");
//结果"http://localhost/index.jsp?a=123&c=456"
url=url.replace(/(?![?&])(a)=\w+/gi,"c=456");
//结果"http://localhost/index.jsp?c=456&c=456"