Imagine this:
a = "('a','b','c'),('d','e','f')"
I am trying to split it using re so that I will get an array of 2 elements, containing "('a','b','c')" and ('d','e','f'). I tried :
matches = re.split("(?:\)),(?:\()",a)
but this gives me the result:
'(2,3,4'
'1,6,7)'
I could parse it, character by character, but if a regex solution is possible, I would prefer it.
You need to split on the comma which is preceded by a
)and followed by a(. But the parenthesis themselves should not be part of the split point. For that you need to use positive lookahead and positive look behind assertions as:See it