Search and replace specific query string parameter value in javascript

后端 未结 6 1593
无人及你
无人及你 2020-12-23 20:07

I have a string which is something like this :

a_href= \"www.google.com/test_ref=abc\";

I need to search for test_ref=abc in thisabove stri

6条回答
  •  粉色の甜心
    2020-12-23 20:55

    Based on this discussion I have fixed the Chris function (problem with regex string!)

    function updateUrlParameter(url, param, value){
        var regex = new RegExp('('+param+'=)[^\&]+');
        return url.replace( regex , '$1' + value);
    }
    

提交回复
热议问题