美文网首页
替换后缀名,只替换最后一个

替换后缀名,只替换最后一个

作者: 价值投机168 | 来源:发表于2021-05-06 17:07 被阅读0次

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

如果是一个变量,需要这样写:
'yyy.csv.pp.csv.csv'.replace(RegExp('(.*)' + this.profile.findTypeItem(info.Type).ext),'$1')

这样,就会将最后一个.csv替换为空白的

相关文章

网友评论

      本文标题:替换后缀名,只替换最后一个

      本文链接:https://www.haomeiwen.com/subject/tepddltx.html