Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #replace #occurrence #letter
ADD COMMENT
Topic
Name
1+8 =