mathiasbynens / emoji-regex

A regular expression to match all Emoji-only symbols as per the Unicode Standard.
https://mths.be/emoji-regex
MIT License
1.73k stars 174 forks source link

Trim down the text emoji regex size #15

Closed gilmoreorless closed 7 years ago

gilmoreorless commented 7 years ago

I noticed the text emoji regex was using an inefficient method of optionally matching the variation selector \uFE0F after \p{Emoji}. Due to all the character class expansions, this ends up bloating the generated regex with duplicate paths. Switching the match to just make \uFE0F optional brings down the size of the generated regex considerably:

> require('./text-old')().source.length
8474
> require('./text-new')().source.length
7093

I also added a looped test for all the \p{Emoji} characters to verify it still matches everything correctly.