Split by comma and how to exclude comma from quotes in split ... Python -
python 2.7 code
cstr = '"aaaa","bbbb","ccc,ddd"' newstr = cstr.split(',') print newstr # result : ['"aaaa"','"bbbb"','"ccc','ddd"' ]
but, want result.
result = ['"aaa"','"bbb"','"ccc,ddd"']
help..
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 delimiter ,
followed double quote "
Comments
Post a Comment