regexp for sequence of quoted strings
gry at ll.mit.edu
gry at ll.mit.edu
Fri May 27 15:21:36 EDT 2005
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
More information about the Python-list
mailing list