or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

emoji-regex

emoji-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.

Package Information

  • Package Name: emoji-regex
  • Package Type: npm
  • Language: JavaScript (with TypeScript definitions)
  • Installation: npm install emoji-regex

Core Imports

const emojiRegex = require('emoji-regex');

ES Module:

import emojiRegex from 'emoji-regex';

TypeScript:

import emojiRegex from 'emoji-regex';

Basic Usage

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}`);
}

Architecture

emoji-regex is designed with the following key characteristics:

  • Function Export Pattern: Exports a function that returns a RegExp rather than exporting the regex directly, preventing accidental mutation of the global regex instance
  • Build-Time Generation: Regex patterns are generated at build time from official Unicode emoji test data using the emoji-test-regex-pattern package
  • Deterministic Results: Each version is tied to a specific Unicode version, ensuring consistent behavior across deployments
  • Global Flag: The returned RegExp has the global flag set for matching multiple emoji in text
  • Unicode Compliance: Matches all emoji according to the Unicode Standard, including complex sequences

Capabilities

Emoji Regex Generation

Creates 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:

  • Basic emoji symbols: ๐Ÿ˜€ ๐Ÿ‘ โค๏ธ
  • Emoji with variation selectors: โ†”๏ธ (text + variation selector)
  • Emoji modifier sequences: ๐Ÿ‘ฉ๐Ÿฟ (base + skin tone modifier)
  • ZWJ sequences: ๐Ÿ‘ฉโ€โœˆ๏ธ (woman + ZWJ + airplane)
  • Flag sequences: ๐Ÿ‡บ๐Ÿ‡ธ (regional indicator symbols)
  • Keycap sequences: 1๏ธโƒฃ (digit + variation selector + combining enclosing keycap)
  • Tag sequences: ๐Ÿด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ (subdivision flags)

Important Notes:

  • Always call emojiRegex() to get a fresh RegExp instance, as the returned regex has the global flag set
  • The regex is generated at build time, so patterns are fixed for each package version
  • Results are deterministic and tied to the Unicode version used during build
  • The regex pattern is optimized for accuracy rather than size or performance