替换后缀名,只替换最后一个
2021-05-06 本文已影响0人
价值投机168
let str = "hello world";
let res = str.replace(/(.*)l/,'1 + 替换后的字符
console.log(res); // hello wor0d
如果是一个变量,需要这样写:
'yyy.csv.pp.csv.csv'.replace(RegExp('(.*)' + this.profile.findTypeItem(info.Type).ext),'$1')
这样,就会将最后一个.csv替换为空白的