๐Ÿ› ๏ธ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

Pertanyaan yang Sering Diajukan

Implementasi Kode

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.