Alternatively string javascript replace the last occurrence of

Project requirements:

Replace the last match

 

Instructions:

replace

 

Use replace match was the first match, or use the g globally match, inconsistent with the requirements

 

Match the last match and replace, you need to use the greedy mode

 

var str = 000p111p222p333
str = str.replace(/(.*)p/, '$1div')
console.log(str)  //000p111p222div333

 

Guess you like

Origin www.cnblogs.com/yuanxinru321/p/10948043.html