nodejs replace code example
Example 1: javascript remove text from string
var str = "That is like so not cool, I was like totally mad.";
var cleanStr = str.replace(/like/g, "");
Example 2: js replace characters in a string
var str = "Original string!";
var str = str.replace("Original", "New");
Example 3: string replace javascript
let re = /apples/gi;
let str = "Apples are round, and apples are juicy.";
let newstr = str.replace(re, "oranges");
console.log(newstr)
output:
"oranges are round, and oranges are juicy."
Example 4: str replace javascript all
str.replace(/abc/g, '');
Example 5: replace in string javascript
const p = 'hello world ! hello everyone ! ';
const regex = /hello/gi;
console.log(p.replace(regex, 'good morning'));
console.log(p.replace('hello', 'good evening'));