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 :: Datatable with static json data source 
Javascript :: join array of objects javascript 
Javascript :: Material-ui bank icon 
Javascript :: windows scroll condition 
Javascript :: js concatenate regex 
Javascript :: live search javascript 
Javascript :: model mongoose 
Javascript :: binary search javascript 
Javascript :: javascript string concat vs + 
Javascript :: how to get current formatted date dd/mm/yyyy in javascript 
Javascript :: logic operators in javascript 
Javascript :: jason in javascript 
Javascript :: ref in functional components 
Javascript :: get json data into object 
Javascript :: build#configuring-commonjs-dependencie 
Javascript :: how to pass basic auth for api in angular 11 
Javascript :: javascript delay some seconds 
Javascript :: react native font awesome 
Javascript :: useformik 
Javascript :: vue select first option default 
Javascript :: populate example in mongoose 
Javascript :: javascript to camelcase 
Javascript :: joi allow additional properties 
Javascript :: react router dom v6 
Javascript :: multiple styles in react native 
Javascript :: get url of page in background script 
Javascript :: ant design charts 
Javascript :: onchange on multiple ids jquery 
Javascript :: number pattern js 
Javascript :: nodejs write to log file 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =