jviereck / regexp.js

A JavaScript implementation of RegExp for debugging purpose.
BSD 2-Clause "Simplified" License
51 stars 8 forks source link

Support ES6 `/u` flag #4

Open mathiasbynens opened 10 years ago

mathiasbynens commented 10 years ago

The /u flag should enable a special parsing mode in which astral ranges can be used, and surrogate pairs only count as a single symbol (i.e. get matched by .).

See the example here, for example: http://mathiasbynens.be/notes/javascript-unicode#astral-ranges Currently regexp.js fails to parse the regular expression with the emoji ranges because ES5 doesn’t support it. But with the /u flag, ES6 will! Here’s a link to the demo page with the example prefilled: http://jviereck.github.io/regexp.js/#regexp=%5B%F0%9F%92%A9-%F0%9F%92%AB%5D&input=%F0%9F%92%AA

More info on the /u flag: http://norbertlindenberg.com/2012/05/ecmascript-supplementary-characters/#RegExp

jviereck commented 10 years ago

Sounds interesting. Thanks a lot for bringing this up! However, this is nothing I plan to work on in the near future but PullRequests are always welcome. If assistance with the code base on how to maybe implement this is required, please reach out to me at any time.

mathiasbynens commented 10 years ago

In order to implement the u flag, the parser would need to be aware of the flags, as different parsing rules apply in that case.

@jviereck Any plans to release the parser as a separate npm package (and simply using it as a dependency for regexp.js)?

jviereck commented 10 years ago

Not until now, but sounds good to me. Will take some days until I get to it - feel free to ping me if I forget about it.

mathiasbynens commented 10 years ago

Ping! :) I’ve filed it as a separate issue so it’s easier to keep track of: #6