const p = 'Dog dog'; const regex = /Dog/gi; console.log(p.replace(regex, 'ferret')); // expected output: "ferret ferret"