Next / Previous / Contents / Shipman's homepage

7.18. quotedString: Parser for a default quoted string

For the common case of a literal string that is bounded by either double ("...") or single ('...') quotes, the variable pp.quotedString is an instance of Section 5.27, “QuotedString: Match a delimited string” that uses that specification for the quote characters.

>>> print pp.quotedString.parseString('"Ftang ftang"')
['"Ftang ftang"']
>>> print pp.quotedString.parseString("'Ole Biscuitbarrel'")
["'Ole Biscuitbarrel'"]

Note that the quotes are returned as part of the result. If you don't like that, you can attach the parse action described in Section 6.15, “removeQuotes(): Strip leading trailing quotes”.

>>> justTheGuts = pp.quotedString.addParseAction(pp.removeQuotes)
>>> print justTheGuts.parseString("'Kevin Phillips Bong'")
['Kevin Phillips Bong']