regexp for sequence of quoted strings

Paul McGuire ptmcg at austin.rr.com
Wed May 25 17:59:13 EDT 2005


Pyparsing includes some built-in quoted string support that might
simplify this problem.  Of course, if you prefer regexp's, I'm by no
means offended!

Check out my Python console session below.  (You may need to expand the
unquote method to do more handling of backslash escapes.)

-- Paul
(Download pyparsing at http://pyparsing.sourceforge.net.)

>>> from pyparsing import delimitedList, sglQuotedString
>>> text = r"'the','dog\'s','bite'"
>>> def unquote(s,l,t):
...     t2 = t[0][1:-1]
...     return t2.replace("\\'","'")
...
>>> sglQuotedString.setParseAction(unquote)
>>> g = delimitedList( sglQuotedString )
>>> g.parseString(text).asList()
['the', "dog's", 'bite']




More information about the Python-list mailing list