Given the string
S = "(45171924,-1,'AbuseFilter/658',2600),(43795362,-1,'!!_(disambiguation)',2600),(45795362,-1,'!!_(disambiguation)',2699)"
I'd like to extract everything within the parentheses UNLESS the parens are inside a quotation. So far I've managed to get everything within parentheses, but I can't figure out how to stop from splitting on the inner parenthesis inside the quotes. My current code is:
import re
S = "(45171924,-1,'AbuseFilter/658',2600),(43795362,-1,'!!_(disambiguation)',2600),(45795362,-1,'!!_(disambiguation)',2699)"
p = re.compile( "\((.*?)\)" )
m =p.findall(S)
for element in m:
print element
What I want is:
45171924,-1,'AbuseFilter/658',2600
43795362,-1,'!!_(disambiguation)',2600
45795362,-1,'!!_(disambiguation)',2699
What I currently get is:
45171924,-1,'AbuseFilter/658',2600
43795362,-1,'!!_(disambiguation
45795362,-1,'!!_(disambiguation
What can I do in order to ignore the internal paren?
Thank you!!
In case it helps, here are the threads I've looked at:
1) REGEX-String and escaped quote