js 正则RegExp对象替换url参数值

// 替换指定传入参数的值,oUrl为链接,paramName为参数,replaceWith为新值
function  replaceParamVal (oUrl, paramName, replaceWith) {
    var re = new RegExp('(' + paramName + '=)([^&]*)', 'gi')
    var nUrl = oUrl.replace(re, paramName + '=' + replaceWith)
    return nUrl
  }
posted @ 2021-10-20 17:53  清和时光  阅读(381)  评论(0编辑  收藏  举报