Plex is a Python module for constructing lexical analysers,
or scanners. Plex scanners have almost all the capabilities of
the scanners generated by GNU Flex, and are specified in a very
similar way. Tokens are defined by regular expressions, and each
token has an associated action, which may be to return a literal
value, or to call an arbitrary function. 

WWW: http://www.cosc.canterbury.ac.nz/~greg/python/Plex/