I'm looking to parse these kinds of strings into lists in Python:
"a,b,c",d,"e,f" => ['a','b','c'] , ['d'] , ['e','f']
"a,b,c",d,e => ['a','b','c'] , ['d'] , ['e']
a,b,"c,d,e,f" => ['a'],['b'],['c','d','e','f']
a,"b,c,d",{x(a,b,c-d)} => ['a'],['b','c','d'],[('x',['a'],['b'],['c-d'])]
It nests, so I suspect regular expressions are out. All I can think of is to start counting quotes and brackets to parse it, but that seems horribly inelegant. Or perhaps to first match quotes and replace commas between them with somechar, then split on commas, until all the nesting is done, and finally re-split on somechar.
Any thoughts?