Next / Previous / Contents / Shipman's homepage

5.20. NotAny: General lookahead condition

pp.NotAny(parser)

This is similar to Section 5.10, “FollowedBy: Adding lookahead constraints” in that it looks to see if the current text position does not match something, but it does not advance that position. In this case the parser argument is any parser. The match succeeds if and only if the text at the current position does not match parser. The current position is not advanced whether parser matches it or not.

In the example below, the pattern matches a sequence of letters, followed by a sequence of digits provided the first one is not '0'.

>>> name = pp.Word(pp.alphas)
>>> num = pp.Word(pp.nums)
>>> nameNum = name + pp.NotAny(pp.Literal('0')) + num
>>> print nameNum.parseString('Woody37')
['Woody', '37']
>>> print nameNum.parseString('Tinny006')
pyparsing.ParseException: Found unwanted token, "0" (at char 5), (line:1,
col:6)