SoFunction
Updated on 2025-03-06

Simple implementation of obtaining parameters in url through regular expressions

url:

?name=charm&id=123

In js:

var name = getUrlParam("name");

/*Get parameters in url through regular
function getUrlParam(name){
   var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
   var r = (1).match(reg);
   if(r!=null)return decodeURI(r[2]); return null;
}

The simple implementation of obtaining parameters in url through regular expressions is all the content I share with you. I hope you can give you a reference and I hope you can support me more.