emoji-regex ![Build status](https://travis-ci.org/mathiasbynens/emoji-regex.svg?branch=master)
emoji-regex offers a regular expression to match all emoji symbols (including textual representations of emoji) as per the Unicode Standard.
This repository contains a script that generates this regular expression based on the data from Unicode Technical Report #51. Because of this, the regular expression can easily be updated whenever new emoji are added to the Unicode standard.
Installation
Via npm:
npm install emoji-regex
In Node.js:
const emojiRegex = require('emoji-regex');
const text = `
\u{231A}: โ default emoji presentation character (Emoji_Presentation)
\u{2194}\u{FE0F}: โ๏ธ default text presentation character rendered as emoji
\u{1F469}: ๐ฉ emoji modifier base (Emoji_Modifier_Base)
\u{1F469}\u{1F3FF}: ๐ฉ๐ฟ emoji modifier base followed by a modifier
`;
let match;
while (match = emojiRegex().exec(text)) {
const emoji = match[0];
console.log(`Matched sequence ${ emoji } โ code points: ${ [...emoji].length }`);
}
Console output:
Matched sequence โ โ code points: 1
Matched sequence โ โ code points: 1
Matched sequence โ๏ธ โ code points: 2
Matched sequence โ๏ธ โ code points: 2
Matched sequence ๐ฉ โ code points: 1
Matched sequence ๐ฉ โ code points: 1
Matched sequence ๐ฉ๐ฟ โ code points: 2
Matched sequence ๐ฉ๐ฟ โ code points: 2
Author
License
emoji-regex is available under the MIT license.