Emoji Text Replacement
Replace common English words with matching emojis to make your text more expressive.
Emoji Dictionary (sample)
love â â€ïžheart â â€ïžhappy â ðsmile â ðlaugh â ðcry â ð¢sad â ð¢angry â ð cool â ðthink â ð€wow â ð®fire â ð¥star â âsun â âïžmoon â ðrain â ð§ïžsnow â âïžcloud â âïždog â ðcat â ðbird â ðŠfish â ðhorse â ðcow â ðpig â ð·rabbit â ð°bear â ð»lion â ðŠtiger â ð¯elephant â ð+89 more words
ãããã質å
ã³ãŒãå®è£
import re
EMOJI_MAP = {
"sun": "âïž", "moon": "ð", "star": "â", "heart": "â€ïž",
"fire": "ð¥", "water": "ð§", "tree": "ð³", "flower": "ðž",
"house": "ð ", "car": "ð", "book": "ð", "music": "ðµ",
"food": "ð", "coffee": "â", "dog": "ð¶", "cat": "ð±",
"money": "ð°", "time": "â°", "phone": "ð±", "computer": "ð»",
"love": "ð", "happy": "ð", "sad": "ð¢", "angry": "ð ",
"eyes": "ð", "hand": "ð", "thumbs up": "ð", "party": "ð",
"snow": "âïž", "rain": "ð§ïž", "lightning": "â¡", "wind": "ð¬ïž",
}
def replace_with_emojis(text: str) -> str:
"""Replace words in text with matching emojis."""
def replace_word(match):
word = match.group(0)
return EMOJI_MAP.get(word.lower(), word)
# Build pattern from longest to shortest to handle multi-word mappings
pattern = r"\b(" + "|".join(
re.escape(k) for k in sorted(EMOJI_MAP.keys(), key=len, reverse=True)
) + r")\b"
return re.sub(pattern, replace_word, text, flags=re.IGNORECASE)
text = "I love the sun, the moon, and the stars. My heart is on fire!"
result = replace_with_emojis(text)
print(result)
# Output: I â€ïž the âïž, the ð, and the â. My â€ïž is on ð¥!Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.