Further tweak regexps, add debug option.

I'm still not happy with this, but it's slightly better.