I am replacing content in a string with a predetermined character based on if the substring is wrapped in quotes.
const string = "The \"quick\" brown \"fox\" 'jumps' over the 'lazy dog'";
const pattern = /(?:'([^']*)')|(?:"([^"]*)")/g;
const redactedText = string.replace(pattern, (str) => {
const strippedString = str.replace(/['"]+/g, '');
return 'x'.repeat(strippedString.length);
}
Output: The xxxxx brown xxx xxxxx over the xxxxxxxx
However I was to preserve the space within lazy dog
So it would output: The xxxxx brown xxx xxxxx over the xxxx xxx
What am I missing to do this?