I want to match strings like:
The sentence is \'He said \"Hello there\"\'
The sentence is \"He said \'Hello there\'\"
and get back a single
You want to make sure the quote symbols are properly matched, so a quote starting with a single quote ends with a single quote. Also, the regex should allow for escaping a quote symbol with a backslash if it's the same symbol (double or single quote symbol) bounding the string. Try this:
"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'
These samples match this regex:
'sing"le q\'uote'
"dou\"ble 'quote"