Minor bug fixes and tests for RegEx and Lexer

This fixes two bugs and one maybe-bug.