js string replaceAll regex code example
Example 1: javascript replaceall
//as of August 2020, not supported on older browsers
str.replaceAll("abc","def")
Example 2: replace javascript
// Replace with no modifiers
let newText = startText.replace("yes", "no")
console.log(newText) // "Yes, I said no, it is, yes."
// Replace with 'g'-global modifier
newText = startText.replace(/yes/g, "no")
console.log(newText) // "Yes, I said no, it is, no."
// Replace with modifiers 'g'-global and 'i'-case insensitive
newText = startText.replace(/yes/gi, "no")
console.log(newText) // "no, I said no, it is, no."