Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js replace all symbols in 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 :: express serve home page 
Javascript :: react how to create range 
Javascript :: replace array element javascript 
Javascript :: node redis json set key 
Javascript :: how do i make a link to direct me to a new page when i click on a button in react 
Javascript :: set variable to object without editing old object js 
Javascript :: how to get all form values in javascript 
Javascript :: javascript string remove backslash 
Javascript :: set headers in express 
Javascript :: how to show day name in javascript using array 
Javascript :: mongoose custom object schema 
Javascript :: convert base64 to image nodejs 
Javascript :: async await anonymous function 
Javascript :: open a particular slide on click button in owl carousel 
Javascript :: new operator in javascript 
Javascript :: sum of digits in a whole number javascript 
Javascript :: string split javascript 
Javascript :: save text to file nodejs 
Javascript :: yarn build react 
Javascript :: dropzone on success all files 
Javascript :: get all links from html javascript 
Javascript :: react native datepicker disable future dates 
Javascript :: unique string id js 
Javascript :: sequelize delete item 
Javascript :: compare two arrays and make sure there are no duplicates js 
Javascript :: json javascript 
Javascript :: js input hidden get value 
Javascript :: js bundle with popper bootstrap 
Javascript :: javascript add to array 
Javascript :: react-router react-router-dom 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =