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