javascript replace last occurrence of a letter code example
Example 1: javascript replace last occurrence of a letter
String.prototype.replaceLast = function (search, replace) {
return this.replace(new RegExp(search+"([^"+search+"]*)$"), replace+"$1");
}
str = "lala";
newStr = str.replaceLast("l", "m");
console.log(newStr);
Example 2: javascript replace last character
var str1 = "Notion,Data,Identity,".replace(/.$/,".")