đŸ› ïžToolsShed

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

Questions Fréquentes

Implémentation du Code

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.