regex find and replace javascript code example
Example 1: replace regex javascript
const p = 'lazy dog. If the dog reacted, was it really lazy?';
const regex = /Dog/ig;
p.replace(regex, 'ferret')
// output: lazy ferret. If the ferret reacted, was it really lazy?
Example 2: replace js
// Replace All
str = str.replace(/_/g, ' ');