PyParsing rocks!  Here's what I ended up with:

def unpack_sql_array(s):
    import pyparsing as pp
    withquotes = pp.dblQuotedString.setParseAction(pp.removeQuotes)
    withoutquotes = pp.CharsNotIn('",')
    parser = pp.StringStart() + \
             pp.Word('{').suppress() + \
             pp.delimitedList(withquotes ^ withoutquotes) + \
             pp.Word('}').suppress() + \
             pp.StringEnd()
    return parser.parseString(s).asList()

unpack_sql_array('{the,dog\'s,"foo,"}')
['the', "dog's", 'foo,']

[[Yes, this input is not what I stated originally.  Someday, when I
reach a higher plane of existance, I will post a *complete* and
*correct* query to usenet...]]

Does the above seem fragile or questionable in any way?
Thanks all for your comments!

-- George

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to