Answers for "replaceall regex javascript"

1

javascript regex replace all

const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';

console.log(p.replaceAll('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"


// global flag required when calling replaceAll with regex
const regex = /Dog/ig;
console.log(p.replaceAll(regex, 'ferret'));

// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
Posted by: Guest on April-19-2022
1

javascript replaceall

//as of August 2020, not supported on older browsers
str.replaceAll("abc","def")
Posted by: Guest on October-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language