I have a string that contains some substrings wrapped in some special characters. Here's my code:
var p = 'The quick brown fox jumps over the lazy [dog]. If the [dog] reacted, was it really lazy?';
var regex = /[\\[dog\\]]/g;
console.log(p.replace(regex, 'ferret'));
The code gives me output The quick brown fox jumps over the lazy ferretdogferret. If the ferretdogferret reacted, was it really lazy? but I am expecting The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?