split string at commas respecting quotes when string not in csv format

Grant Edwards invalid at invalid
Thu Mar 26 17:19:23 EDT 2009


On 2009-03-26, R. David Murray <rdmurray at bitdance.com> wrote:
> Tim Chase <python.list at tim.thechases.com> wrote:
>>    r = re.compile(r"""
>>      (\w+)
>>      \s*=\s*(
>>      "(?:[^"]*)"
>>      |
>>      [^,]+
>>      )
>>      """, re.VERBOSE)
>>    results = [
>>      (m.group(1), m.group(2).strip('"'))
>>      for m in r.finditer(s)
>>      ]
>> 
>> Things like internal quoting ('b="123\"456", c="123""456"') would 
>> require a slightly smarter parser.
>
> Thank you thank you.

We'll wait until you need to modify that and then ask if you're
still grateful.  ;)

"There once was a programmer who had a problem..."

-- 
Grant Edwards                   grante             Yow! I'm a fuschia bowling
                                  at               ball somewhere in Brittany
                               visi.com            



More information about the Python-list mailing list