Blog
Remove emojis from a string with regex
Removing emojis is a common pre-processing step for plain-text storage, SMS gateways, or terminal output. Here's how to do it in three languages.
The basic approach: match Unicode code points in the emoji blocks and replace with empty string.
JavaScript
function stripEmojis(s) {
return s.replace(/[\u{1F300}-\u{1F9FF}\u{2600}-\u{27BF}\u{2300}-\u{23FF}]/gu, "");
}
stripEmojis("Hello 👋 world 🌍!"); // "Hello world !"
The u flag is critical — without it, the brace-escape syntax doesn't work and surrogate pairs aren't handled correctly.
Python
import re
EMOJI_RE = re.compile(
"["
"\U0001F300-\U0001F9FF"
"\u2600-\u27BF"
"\u2300-\u23FF"
"]",
flags=re.UNICODE,
)
def strip_emojis(s):
return EMOJI_RE.sub("", s)
print(strip_emojis("Hello 👋 world 🌍!"))
Go
import (
"regexp"
"fmt"
)
var emojiRE = regexp.MustCompile(\`[\x{1F300}-\x{1F9FF}\x{2600}-\x{27BF}\x{2300}-\x{23FF}]\`)
func stripEmojis(s string) string {
return emojiRE.ReplaceAllString(s, "")
}
Edge cases this misses
The basic emoji blocks don't cover everything:
- Skin-tone modifiers (U+1F3FB–U+1F3FF) — append
\u{1F3FB}-\u{1F3FF}to the class. - Zero-Width Joiner sequences like 👨👩👧 — multiple emoji + ZWJ. The regex above strips each emoji but leaves orphan ZWJ characters.
- Flag emoji like 🇮🇳 — pairs of regional indicator symbols (U+1F1E6–U+1F1FF).
- Newer emoji blocks like Symbols and Pictographs Extended-A (U+1FA70–U+1FAFF).
For complete coverage, use a library: emoji in Python, emoji-regex in JavaScript, github.com/forPelevin/gomoji in Go.