Next / Previous / Contents / Shipman's homepage

6.15. removeQuotes(): Strip leading trailing quotes

To remove the first and last characters of the matched text from the result, use this function as a parse action.

>>> slashPat = pp.Combine(pp.Literal('/') + pp.Word(pp.alphas) +
...                       pp.Literal('/'))
>>> print slashPat.parseString('/Llamas/')
['/Llamas/']
>>> slash2 = slashPat.addParseAction(pp.removeQuotes)
>>> print slash2.parseString('/Llamas/')
['Llamas']