Next / Previous / Contents / Shipman's homepage

5.2. And: Sequence

pp.And([expr, ...])

The argument is a sequence of ParseExpression instances. The resulting parser matches a sequence of items that match those expressions, in exactly that order. You may also use the Python “+” operator to get this functionality. Here are some examples:

>>> letterDigit = pp.And([pp.Word(pp.alphas, exact=1),
...                       pp.Word(pp.nums, exact=1)])
>>> print letterDigit.parseString('x5')
['x', '5']
>>> digitsLetters = pp.Word(pp.nums) + pp.Word(pp.alphas)
>>> print digitsLetters.parseString('23skiddoo')
['23', 'skiddoo']
>>>