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

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -