Simplify the implementation by using a regular expression

Based on the one used in `he`, i.e. https://gist.github.com/mathiasbynens/bbe7f870208abcfec860.
Merge pull request #1 from mathiasbynens/regex

Simplify the implementation by using a regular expression