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
Post a Comment