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 -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

java - How to implement an entity bound odata action in olingo v4.3 -