How can I use Unicode-aware regular expressions in JavaScript?

Situation for ES 6

The ECMAScript language specification, edition 6 (also commonly known as ES2015), includes Unicode-aware regular expressions. Support must be enabled with the u modifier on the regex. See Unicode-aware regular expressions in ES6 for a break-down of the feature and some caveats.

ES6 is widely adopted in both browsers and stand-alone Javascript runtimes such as Node.js, so using this feature won’t require extra effort in most cases. Full compatibility list: https://kangax.github.io/compat-table/es6/

Situation for ES 5 and below (legacy browsers)

There is a transpiler named regexpu that translates ES6 Unicode regular expressions into equivalent ES5. It can be used as part of your build process. Try it out online..

Even though JavaScript operates on Unicode strings, it does not implement Unicode-aware character classes and has no concept of POSIX character classes or Unicode blocks/sub-ranges.

Leave a Comment