Simplify the implementation by using a regular expression

Based on the one used in `he`, i.e. https://gist.github.com/mathiasbynens/bbe7f870208abcfec860.