Questions regarding ES6 Unicode regular expressions

Allen Wirfs-Brock allen at
Tue Aug 26 10:01:20 PDT 2014

I've thought about this a bit. I was initially inclined to agree with the idea of extending the existing character classes similar to what Mathias' proposes.  But I now think that is probably not a very good idea and that what is currently spec'ed (essentially that the /u flag doesn't change the meaning of \w, \d, etc.) is the better path.

The basic issue I see is backwards compatibility and evolving code to using /u patterns.

I suspect that there is plenty of JS code in the world that does something more or less equivalent to `parseInt(/\s*(\d+)/.exec(input)[1])`

Note that `parseInt` is only prepared to recognize the digits U+0030-U+0039.

I t seems to me, that we want programmers to start migrating to full Unicode regular expressions without having to do major logic rewrite of their code.  For example, ideally the above expression could simply be replaced by `parseInt(/\s*(\d+)/u.exec(input)[1])` and everything in the application could continue to work unchanged.

That won't be the case if we redefine, as Mathias proposes, `/\d/u` to be equivalent to 
rather than

We can apply similar logic to \w and even \s.
Instead, we should leave the definitions of \d, \w and \s unchanged and plan to adopt the already established convention that `\p{<Unicode property>}` is the notation for matching Unicode categories. See 
I think digesting all the \p{} possibilities is too much to do for ES6, so I suggest that for ES6 that we simply reserve the \p{<characters>} and \P{<characters>} syntax within /u patterns.  A \p proposal can then be developed for ES7.
I see one remaining issue:
In ES5 (and ES6): `/a-z/i`  does not match U+017F (ſ) or U+212A (K) because the ES canonicalization algorithm excludes mapping code points > 127 that toUpperCase to code points <128.
However, as currently spec'ed, the ES6 canonicalization algorithm for /u RegExps does not include that >127/<128 exclusion.  It maps U+017F to "S" which matches. 
This is probably a minor variation, from the ES5 behavior, but we should probably be sure it is a desirable and tolerable change as we presumably could also apply the >127/<128 filter to /u canonicalization.

So, here is a summary of my proposal:
1) don't change the current definitions of \d, \w, \s when used in /u regular expressions.
2) Decide whether the current ES6 /u canonicalization algorithm is correct or if it should not translated code points > 127 that map to code points <128.
3) Reserve within /u RegExp patterns, the syntax \p{<characters>} and \P{<characters>}
4) Start to develop a \p{ } proposal for ES7.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list