Re-implement using a regex

This also implements the ideas suggested in #16, but adds no tests for it.