Right now, this regex is doing the opposite of what I want. It’s removing everything that’s inside double quotes:
const text = `"This is inside quotes."
This is outside quotes.
"This is inside quotes," I said.`
const quotesRegex = /((")[^"n]*)("|n)/g
const result = text.replace(quotesRegex, '')
console.log(result)
How can invert this regex so it removes everything that’s NOT inside double quotes? In other words, in my example, only "This is inside quotes."
and "This is inside quotes,"
will remain.
Note: the regex might not be perfect, but it has worked for me for years.
Note 2: it also matches when there’s an opening quote and a new line without a closing quote.