regex - python combining 2 regexes that search strings within single and double quotes -


i have regex extracts everything between 2 double quotes , regex same 2 single quotes. strings within quotes can include escaped quotes. i'd make these 2 expressions single one:

1) re.findall(r'"(.*?)(?<!\)"', string)

2) re.findall(r"'(.*?)(?<!\)'", string)

so like:

1+2) re.findall(r"'|\"(?<!\)['|\"]", string)

but isn't working.

i'd have 'abc\"\"' "abc\'\'" evaluated using same regex. 'abc\"\"" isn't expected work. if quotes exchanged, allow same regex work on also. possible?

not sure understood wanted possible reuse value of captured group in regex.
may following pattern job:
(['"])(.*)\1

explanation:
(['"]) : quote or double-quote captured first group
(.*) : second group captures everything...
\1 : ...until first group value met again
result available in second group


Comments