Moved some regexes around to pass unit tests correctly.

Also updated unit tests to use next(gen) for Python 2 support