Next / Previous / Contents / Shipman's homepage

5.17. Literal: Match a specific string

pp.Literal(text)

Matches the exact characters of the text argument. Here are some examples.

>>> name = pp.Word(pp.alphas)
>>> pat = pp.Literal('x') + name
>>> print pat.parseString('xyz')
['x', 'yz']
>>> print pat.parseString('abc')
pyparsing.ParseException: Expected "x" (at char 0), (line:1, col:1)