javascript - replacing the value of a variable in url -



javascript - replacing the value of a variable in url -

so have url mentioned in next example; want alter value of pagetoken "baz"; next effort replacing pagetoken well; right way alter value of pagetoken?

var url = "https://www.googleapis.com/youtube/v3/search?&pagetoken=cdiqaq&foo=bar" var res = url.replace(/pagetoken=\w*/g, "baz"); console.log(res); //res now: https://www.googleapis.com/youtube/v3/search?&baz&foo=bar, desired output https://www.googleapis.com/youtube/v3/search?&pagetoken=baz&foo=bar

thanks

this work also:

var res = url.replace(/(pagetoken=)\w*/g, "$1baz");

javascript regex node.js

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -