除了引号之外,Python正则表达式括号内的所有内容

鉴于字符串

S = "(45171924,-1,'AbuseFilter/658',2600),(43795362,-1,'!!_(disambiguation)',2600),(45795362,-1,'!!_(disambiguation)',2699)"

我想提取括号内的所有内容,除非parens在引号内.到目前为止,我已经设法将所有内容都放在括号内,但我无法弄清楚如何停止在引号内的内括号上拆分.
我目前的代码是:

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

我想要的是:

45171924,-1,'AbuseFilter/658',2600
43795362,-1,'!!_(disambiguation)',2600
45795362,-1,'!!_(disambiguation)',2699

我目前得到的是:

45171924,-1,'AbuseFilter/658',2600
43795362,-1,'!!_(disambiguation
45795362,-1,'!!_(disambiguation

我怎么办才能忽视内部人员呢?

谢谢!!

如果它有帮助,这里是我看过的线程:

1)REGEX-String and escaped quote

2)Regular expression to return text between parenthesis

3)Get the string within brackets in Python

最佳答案
您可以使用非捕获组来断言逗号或字符串的结尾如下:

p = re.compile(r'\((.*?)\)(?:,|$)')

Working Demo

转载注明原文:除了引号之外,Python正则表达式括号内的所有内容 - 代码日志