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

R. David Murray rdmurray at bitdance.com
Thu Mar 26 15:51:34 EDT 2009


OK, I've got a little problem that I'd like to ask the assembled minds
for help with.  I can write code to parse this, but I'm thinking it may
be possible to do it with regexes.  My regex foo isn't that good, so if
anyone is willing to help (or offer an alternate parsing suggestion)
I would be greatful.  (This has to be stdlib only, by the way, I
can't introduce any new modules into the application so pyparsing is
not an option.)

The challenge is to turn a string like this:

    a=1,b="0234,)#($)@", k="7"

into this:

    [("a", "1"), ("b", "0234,)#($)#"), ("k", "7")]

--
R. David Murray             http://www.bitdance.com




More information about the Python-list mailing list