JAVASCRIPT
Remove Emojis from a String
Cleanse user input or normalize text by efficiently removing various Unicode emojis using a comprehensive regular expression pattern.
function removeEmojis(text) {
// Regex to match most common emoji ranges and specific emoji characters
const emojiRegex = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g;
return text.replace(emojiRegex, '');
}
// Example usage:
// const message = "Hello 👋, how are you today? 😀 This is a test. 🚀";
// console.log(removeEmojis(message));
How it works: This JavaScript function removes most common emojis from a string. It uses a regular expression `emojiRegex` that encompasses various Unicode ranges and specific characters frequently used for emojis, including pictographs, symbols, and surrogate pair combinations. By using the `replace` method with the global flag `g` and an empty string as the replacement, all detected emojis are effectively stripped from the input text.