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