- Instant help with your JavaScript coding problems

Remove emojis from a string with JavaScript

Question:
How to remove emojis from a string with JavaScript?
Answer:
const removeEmojis = (text) => {
    if (!text) {
        return '';
    }
    return text.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, '');
}
Description:

Sometimes user inputs or API responses contains special characters like emojis. These special characters can cause problems later when saving data, for example, if the database does not support UTF-16 characters. But they can also be a problem from a design standpoint. In these cases, it may be necessary to remove the emojis from the text, which can be easily done with the replace method.

Example input text: This is a text with emojis 😃👽🤷‍♂️🦊❤️

Output: This is a text with emojis

Share "How to remove emojis from a string with JavaScript?"
Related snippets:
Tags:
remove, delete, emoji, icon, string, javascript
Technical term:
Remove emojis from a string with JavaScript