python3 extract :)字符串中的符号

问题描述

我找到了各种用于粘贴表情符号和表情符号的工具,但是它们都不在从字符串中提取简单的“ :)”:

from emot.emo_unicode import UNICODE_EMO,EMOTICONS
":)" in EMOTICONS
>>>False

我尝试使用replace将所有“ :)”转换为':‑ \)',但仍然无法正常工作。看起来很简单,但是我在互联网上找不到任何示例。

谢谢。

解决方法

import re

s = 'Pull the emoticon :):) out ):'
(news,count) = re.subn(r'(\s*:\)\s*)',' ',s)
# 'Pull the emoticon out ):'

print('new string',news)
print('count',count)