Answers for "js replace multiple occurrences"

16

javascript replace all occurrences of string

function replaceAll(str, find, replace) {
    var escapedFind=find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    return str.replace(new RegExp(escapedFind, 'g'), replace);
}
//usage example
var sentence="How many shots did Bill take last night? That Bill is so crazy!";
var blameSusan=replaceAll(sentence,"Bill","Susan");
Posted by: Guest on July-22-2019
6

str replace javascript all

str.replace(/abc/g, '');
Posted by: Guest on May-16-2020
0

js replace multiple

string.replace('find1', 'replace1').replace('find2', 'replace2');
Posted by: Guest on August-04-2021

Code answers related to "js replace multiple occurrences"

Code answers related to "Javascript"

Browse Popular Code Answers by Language