Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

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
Comment

js replace last occurrence of string

str = str.replace(new RegExp(list[i] + '$'), 'finish');
Comment

PREVIOUS NEXT
Code Example
Javascript :: reverse a string while keeping spaces in javascript 
Javascript :: load external javascript from console 
Javascript :: javascript window.onpopstate example 
Javascript :: const is available in es6 
Javascript :: set body id js 
Javascript :: js some array 
Javascript :: javascript hello world 
Javascript :: is knex built into node js 
Javascript :: js convert string to date 
Javascript :: Material-ui add photo icon 
Javascript :: delete element of array javascript 
Javascript :: javascript null check 
Javascript :: operator to return specific data of a mongodb query 
Javascript :: discord.js random output 
Javascript :: javascript check for duplicates in array 
Javascript :: javascript loop replace object values using function 
Javascript :: array index javascript show only first 2 elements 
Javascript :: opencage reverse geocoding example 
Javascript :: read files in node js 
Javascript :: js fetch catch 401 
Javascript :: add button dynamically in javascript 
Javascript :: shuffle an array 
Javascript :: moment clone 
Javascript :: dropzone react view photo 
Javascript :: remove from array javascript 
Javascript :: count in string javascript 
Javascript :: javascript things to remember 
Javascript :: typescript vs javascript 
Javascript :: makeStyles is not longer exported from @mui/material/styles 
Javascript :: js import export 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =