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"); str.replace(/abc/g, '');str = str.replace(/abc/g, '');
Also in JavaScript:
- express ssl
- javascript default parameters
- how to set default value in input field in angularjs
- set and get array inside cookie in javascript
- jquery get version
- javascript get day
- find base url in javascript
- how to get session javascript ws3schools
- js clone array
- javascript load image programmatically
- how to find out which version of React
- js how to hide an image
- DataTables warning: table id=example-dt - Invalid JSON response.
- jquery clear form values
- react cloud foundry nginx 404
- shift js mdn
- angular copy
- js array map
- foreach async typescript
- js scroll page horizontally with mouse wheel
- javascript cash register
- map a keys from an array in a separate arraylist javascript
- nested array loop in javascript
- javascript difference between two dates in days