Answers for "how to find last occurrence comma in a string and replace with value in javascript"

0

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);
Posted by: Guest on May-31-2021
0

how to find last occurrence comma in a string and replace with value in javascript

var str = 'a_b_c',
    replacement = '!';

console.log(  str.replace(/_([^_]*)$/, replacement + '$1')  ) //a_b!c
Posted by: Guest on September-29-2021

Code answers related to "how to find last occurrence comma in a string and replace with value in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language