Emoji Text Replacement
将常见英文单词替换为匹配的表情符号,使文本更具表现力。
表情符号词典(示例)
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 更多单词
关于此工具
表情符号文本替换是一个有趣的工具,通过将常见英文词汇替换为相应的表情符号来增强文本的视觉表达力。无论你是在创作社交媒体文章、聊天信息还是非正式邮件,这个工具都能将你的文本瞬间转换为更加色彩斑斓且引人注目的形式,从而更生动地传达情感。
使用方法非常简单—只需将你的文本粘贴或输入到输入框中,工具就会自动将符合条件的词汇替换为对应的表情符号。例如,"love"会变成❤️,"sun"会变成☀️,"pizza"会变成🍕。你可以直接复制结果用于消息、帖子或文档中。替换是有选择性的且考虑上下文的,因此只有明确的名词会被替换,这样可以保持信息的可读性。
这个工具最适合在社交媒体评论、文本消息或友好的邮件等非正式场景中使用,这些情况下使用表情符号很自然且受欢迎。需要注意的是,并非所有单词都有直接对应的表情符号,因此一些不太常见的词汇可能保持不变。工具尊重你的原始文本结构,确保大小写和标点符号得以保留。
常见问题
代码实现
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.