I saw the {Emoji}
and other Unicode character class escapes in some answers to achieve the goal, but no one explains how they work, which have been part of the baseline since July 2015:
\p{...}
, \P{...}
- MDN DocsAfter reviewing the mentioned tables, the most promising one seems to be Extended_Pictographic
:
function removeEmojis(str) {
return str.replace(/[\p{Extended_Pictographic}]/gu, '');
}
let text = "Hello 🌍! This is a test with ❤️ and 123. 😃";
let cleanedText = removeEmojis(text);
console.log(cleanedText); // "Hello ! This is a test with and 123."