1 # emoji-regex [![Build status](https://travis-ci.org/mathiasbynens/emoji-regex.svg?branch=master)](https://travis-ci.org/mathiasbynens/emoji-regex)
3 _emoji-regex_ offers a regular expression to match all emoji symbols (including textual representations of emoji) as per the Unicode Standard.
5 This repository contains a script that generates this regular expression based on [the data from Unicode v12](https://github.com/mathiasbynens/unicode-12.0.0). Because of this, the regular expression can easily be updated whenever new emoji are added to the Unicode standard.
9 Via [npm](https://www.npmjs.com/):
12 npm install emoji-regex
15 In [Node.js](https://nodejs.org/):
18 const emojiRegex = require('emoji-regex');
19 // Note: because the regular expression has the global flag set, this module
20 // exports a function that returns the regex rather than exporting the regular
21 // expression itself, to make it impossible to (accidentally) mutate the
22 // original regular expression.
25 \u{231A}: β default emoji presentation character (Emoji_Presentation)
26 \u{2194}\u{FE0F}: βοΈ default text presentation character rendered as emoji
27 \u{1F469}: π© emoji modifier base (Emoji_Modifier_Base)
28 \u{1F469}\u{1F3FF}: π©πΏ emoji modifier base followed by a modifier
31 const regex = emojiRegex();
33 while (match = regex.exec(text)) {
34 const emoji = match[0];
35 console.log(`Matched sequence ${ emoji } β code points: ${ [...emoji].length }`);
42 Matched sequence β β code points: 1
43 Matched sequence β β code points: 1
44 Matched sequence βοΈ β code points: 2
45 Matched sequence βοΈ β code points: 2
46 Matched sequence π© β code points: 1
47 Matched sequence π© β code points: 1
48 Matched sequence π©πΏ β code points: 2
49 Matched sequence π©πΏ β code points: 2
52 To match emoji in their textual representation as well (i.e. emoji that are not `Emoji_Presentation` symbols and that arenβt forced to render as emoji by a variation selector), `require` the other regex:
55 const emojiRegex = require('emoji-regex/text.js');
58 Additionally, in environments which support ES2015 Unicode escapes, you may `require` ES2015-style versions of the regexes:
61 const emojiRegex = require('emoji-regex/es2015/index.js');
62 const emojiRegexText = require('emoji-regex/es2015/text.js');
67 | [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
69 | [Mathias Bynens](https://mathiasbynens.be/) |
73 _emoji-regex_ is available under the [MIT](https://mths.be/mit) license.