Lexical scanner using regex written for Python 2.7