specific code as follows:

 / * * / var setReferArgs key object definition (referArgs = function) {var = new (Object); referArgs['#userID#'] = userId; referArgs['#userName#'] = userName; return referArgs;} / * * / VAR to replace the URL parameter replaceUrlParams = function (URL) {var actualUrl = "var"; referArgs = (setReferArgs); for (VaR key in referArgs var (EVAL) {e = +'/g'; actualUrl = key'/'+) url.replace (E, referArgs[key]); url = actualUrl;} return actualUrl;}

Chestnut: "http://10.0.0.250:8088/test? UesrID=#userID#" replaced the corresponding value "http://10.0.0.250:8088/test? UesrID=12345";

to replace "http://10.0.0.250:8088/test/#userID#" with "http:/ /10.0.0.250:8088/1234 the corresponding numerical 5 "

js extension: use regular expressions to obtain the parameter values of

 / / get the parameters from the URL value of function getvl from URL (name) {var reg = new RegExp (" (|& ^|\?) "+ name +" ([^& =]* (;) \s|& |$) "," I "); if (reg.test (location.href) return (RegExp.$2.replace) unescape (/+/g")); "return";}; VAR code = getvl ("code"); 

: "the summary of the above method parameters Xiaobian to introduce JS regular expressions to replace the URL, I hope to help you, if you have any questions please give me a message, Xiao Bian will reply you timely. Thank you for your support for the home website of the script!

This paper fixed link:http://www.script-home.com/a-method-of-replacing-url-parameters-by-js-regular-expressions.html | Script Home | +Copy Link

Article reprint please specify:A method of replacing URL parameters by JS regular expressions | Script Home

You may also be interested in these articles!