Next / Previous / Contents / Shipman's homepage

7.20. sglQuotedString: String enclosed in '...'

The variable pp.sglQuotedString is a parser that matches a string enclosed in single-quote (“'”) characters. The sequence “\'” within the text is not interpreted as an internal single-quote character.

>>> text = "'Do I get wafers with it?'"
>>> print pp.sglQuotedString.parseString(text)
["'Do I get wafers with it?'"]
>>> escaper = "'Don\\'t'"
>>> print escaper
'Don\'t'
>>> result = pp.sglQuotedString.parseString(escaper)
>>> print result[0]
'Don\'t'

If internal "\'" sequences were interpreted as escapes, the last line above would have displayed as:

"Don't"