javascript - JQuery: replace string with regex -
i have string this:
var stringa = "id=3&staffid=4&projectid=5"; how use regex replace value of staffid=4 staffid=10?
any great
you want replace staffid use following regexp pattern,
check demo jsfiddle
jquery
str = "id=3&staffid=4&projectid=5"; str = str.replace(/staffid=\d/g, "staffid=10"); console.log(str); console result
id=3&staffid=10&projectid=5 same way can change id, staffid , projectid using /id=(\d+)&staffid=(\d+)+&projectid=(\d+)/g, regexp pattern,
jquery
str = "id=3&staffid=12&projectid=5"; str = str.replace(/id=(\d+)&staffid=(\d+)+&projectid=(\d+)/g, "id=1&staffid=2&projectid=3"); console.log(str); console result
id=1&staffid=2&projectid=3 check demo hope you!
Comments
Post a Comment