A regular expression to match all Emoji-only symbols as per the Unicode Standard.
npx @tessl/cli install tessl/npm-emoji-regex@10.5.0emoji-regex offers a regular expression to match all emoji symbols and sequences (including textual representations of emoji) as per the Unicode Standard. It generates its regex patterns at build time from official Unicode emoji test data, ensuring accuracy and up-to-date emoji support with each Unicode release.
npm install emoji-regexconst emojiRegex = require('emoji-regex');ES Module:
import emojiRegex from 'emoji-regex';TypeScript:
import emojiRegex from 'emoji-regex';const emojiRegex = require('emoji-regex');
const text = `
โ: default emoji presentation character
โ๏ธ: default text presentation character rendered as emoji
๐ฉ: emoji modifier base
๐ฉ๐ฟ: emoji modifier base followed by a modifier
`;
// Get a fresh regex instance (required because regex has global flag)
const regex = emojiRegex();
for (const match of text.matchAll(regex)) {
const emoji = match[0];
console.log(`Matched sequence ${emoji} โ code points: ${[...emoji].length}`);
}emoji-regex is designed with the following key characteristics:
emoji-test-regex-pattern packageCreates a regular expression that matches all emoji symbols and sequences as per the Unicode Standard.
/**
* Returns a regular expression to match all emoji symbols and sequences
* @returns {RegExp} A global regular expression for matching emoji
*/
function emojiRegex(): RegExp;Usage Examples:
const emojiRegex = require('emoji-regex');
// Basic emoji matching
const regex = emojiRegex();
const text = "Hello ๐ world ๐!";
const matches = text.match(regex);
console.log(matches); // ['๐', '๐']
// Using with matchAll for detailed information
for (const match of text.matchAll(regex)) {
console.log(`Found emoji: ${match[0]} at position ${match.index}`);
}
// Testing if text contains emoji
const hasEmoji = emojiRegex().test("Check this out! ๐");
console.log(hasEmoji); // true
// Removing emoji from text
const cleanText = "Hello ๐ world ๐!".replace(emojiRegex(), '');
console.log(cleanText); // "Hello world !"Supported Emoji Types:
The regex matches all types of emoji sequences including:
Important Notes:
emojiRegex() to get a fresh RegExp instance, as the returned regex has the global flag set