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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -