Javascript regex match number after string -


i have string

/results?radius=4000&newfilter=true 

and need replace radius=4000 radius=n n variable.

how can use string.replace() method regex match part?

you can use /radius=\d+/ match "radius=" followed number of digits. can use replace() method replace desired value:

var str = "/results?radius=4000&newfilter=true";  var replacement = 123;    var newstr = str.replace(/radius=\d+/, "radius=" + replacement);    console.log(newstr);


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -