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

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -