import rerx = r"(?:\([^()]*\)|[^,])+"s = 'test,Test,NEAR(this,that,DISTANCE=4),test again,"another test"'print(re.findall(rx, s))
Standard input is empty
['test', 'Test', 'NEAR(this,that,DISTANCE=4)', 'test again', '"another test"']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!