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
Domande Frequenti
Implementazione del Codice
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.