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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

Command prompt result in label. Python 2.7 -