Split by comma and how to exclude comma from quotes in split

The solution using re.split() function:

import re

cStr=""aaaa","bbbb","ccc,ddd""
newStr = re.split(r',(?=")', cStr)

print newStr

The output:

['"aaaa"', '"bbbb"', '"ccc,ddd"']

,(?=") – lookahead positive assertion, ensures that delimiter , is followed by double quote "

Leave a Comment

tech