Next / Previous / Contents / Shipman's homepage

5.14. Keyword: Match a literal string not adjacent to specified context

pp.Keyword(matchString, identChars=I, caseless=False)

The matchString argument is a literal string. The resulting parser will match that exact text in the input. However, unlike the Literal class, the next input character must not be one of the characters in I. The default value of the identChars argument is a string containing all the letters and digits plus underbar (“_”) and dollar sign (“$”).

If you provide the keyword argument caseless=True, the match will be case-insensitive.

Examples:

>>> key=pp.Keyword('Sir')
>>> print key.parseString('Sir Robin')
['Sir']
>>> print key.parseString('Sirrah')
pyparsing.ParseException: Expected "Sir" (at char 0), (line:1, col:1)