What is emojibase-regex?
The emojibase-regex npm package provides regular expressions for matching emoji characters and sequences. It is useful for developers who need to identify, extract, or manipulate emoji in text.
What are emojibase-regex's main functionalities?
Match all emoji
This feature allows you to match all emoji characters in a given text string. The regular expression provided by emojibase-regex can be used to find all emoji in a text.
const emojiRegex = require('emojibase-regex');
const text = 'Hello, world! 🌍😊';
const matches = text.match(emojiRegex);
console.log(matches); // ['🌍', '😊']
Match emoji sequences
This feature allows you to match complex emoji sequences, such as family emojis or flag sequences. The sequences regex is specifically designed to handle these multi-character emoji.
const emojiRegex = require('emojibase-regex/sequences');
const text = 'Family: 👨👩👧👦';
const matches = text.match(emojiRegex);
console.log(matches); // ['👨👩👧👦']
Match emoji with skin tones
This feature allows you to match emoji that include skin tone modifiers. The tones regex is designed to recognize these variations.
const emojiRegex = require('emojibase-regex/tones');
const text = 'Thumbs up: 👍🏽';
const matches = text.match(emojiRegex);
console.log(matches); // ['👍🏽']
Other packages similar to emojibase-regex
emoji-regex
The emoji-regex package provides a regular expression to match all emoji symbols and sequences. It is similar to emojibase-regex but does not offer separate regexes for sequences or skin tones.
twemoji-parser
The twemoji-parser package from Twitter's Twemoji project provides utilities to parse and extract emoji from text. It offers more comprehensive parsing capabilities but is more complex and heavier than emojibase-regex.
node-emoji
The node-emoji package provides a simple way to find and replace emoji in text. It includes a dictionary of emoji names and their corresponding characters, but it does not focus on regular expressions like emojibase-regex.
Emojibase Regex
Install the package.
yarn add emojibase-regex
Import and use the RegExp
pattern.
import EMOJI_REGEX from 'emojibase-regex';
import EMOTICON_REGEX from 'emojibase-regex/emoticon';
import SHORTCODE_REGEX from 'emojibase-regex/shortcode';
import SHORTCODE_NATIVE_REGEX from 'emojibase-regex/shortcode-native';
`🏰`.match(EMOJI_REGEX);
':)'.match(EMOTICON_REGEX);
':castle:'.match(SHORTCODE_REGEX);
':гвинея:'.match(SHORTCODE_NATIVE_REGEX);
Documentation
https://emojibase.dev/docs/regex