Add `toString` method and make `regex` use it internally

Fixes #2.