Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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

PREVIOUS NEXT
Code Example
Javascript :: rounding off numbers javascript 
Javascript :: how to find closest img tag in jquery 
Javascript :: how to fetch the all input element id value 
Javascript :: react router multiple path 
Javascript :: Type io.invertase.firebase.BuildConfig is defined multiple times 
Javascript :: JavaScript Built-in Constructors 
Javascript :: history.push 
Javascript :: download canvas js 
Javascript :: fetch data flutter json 
Javascript :: jquery select div in div 
Javascript :: text align in javascript 
Javascript :: regex match everything except 
Javascript :: dropdown option selection change event in jquery 
Javascript :: javascript add days to date 
Javascript :: can filter be used on objects in javascript 
Javascript :: mongodb import from json 
Javascript :: bignumber to number javascript 
Javascript :: run build version react 
Javascript :: dart list files in directory 
Javascript :: jquery has attribute 
Javascript :: check undefined in javascript 
Javascript :: JS retrieve a String’s size 
Javascript :: javascript click events 
Javascript :: javascript sum of array 
Javascript :: ecmascript compose 
Javascript :: javascript write text 
Javascript :: get form data serialize jquery 
Javascript :: reset redux form after validation 
Javascript :: javascript append item to array 
Javascript :: react router dom 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =