I have this python script. That uses some regular expression. I want to split the string s, but commas while ignoring any commas that exists within the brackets.
s = """aa,bb,(cc,dd),m(ee,ff)"""
splits = re.split(r'\s*(\([^)]*\)|[^,]+)', s, re.M|re.S)
print('\n'.join(splits))
Actual output:
aa
,
bb
,
(cc,dd)
,
m(ee
,
ff)
Desired output:
aa
bb
(cc,dd)
m(ee,ff)
So I can't make it handle having text outside the brackets. Was hoping someone could help me out.