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.