Next / Previous / Contents / Shipman's homepage

5.32. Suppress: Omit matched text from the result

pp.Suppress(p)

An instance of this class is a parser that matches the same content as parser p, but when it matches text, the matched text is not deposited into the returned ParseResult instance.

>>> name = pp.Word(pp.alphas)
>>> lb = pp.Literal('[')
>>> rb = pp.Literal(']')
>>> pat1 = lb + name + rb
>>> print pat1.parseString('[Pewty]')
['[', 'Pewty', ']']
>>> pat2 = pp.Suppress(lb) + name + pp.Suppress(rb)
>>> print pat2.parseString('[Pewty]')
['Pewty']

See also the .suppress() method in Section 5.1, “ParserElement: The basic parser building block”.