Simplify the logic to a single regex. Fixes #5.