js replace 如何替换字符串中的最后一个匹配项

正则表达时,贪婪模式,.*会一直匹配到最后一个

// 验证
let str = "hello world";
let res = str.replace(/(.*)l/,'$10');   //$1 + 替换后的字符
console.log(res); // hello wor0d

 

posted @ 2019-12-24 13:55  WXUECHAO  阅读(6785)  评论(0编辑  收藏  举报