Simplify the implementation by using a regular expression

Based on [the one used in `he`](https://github.com/mathiasbynens/he/blob/78bc2bbc95a82d03bfe02247a110db32cfe5854b/he.js#L53), i.e. https://gist.github.com/mathiasbynens/bbe7f870208abcfec860.