200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 从Python字符串中删除表情符号

从Python字符串中删除表情符号

时间:2024-07-21 00:34:56

相关推荐

从Python字符串中删除表情符号

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ✊

✊ ✊ ✊ ✊ ✊ ✊ ✊ ✊

过滤方法

Python怎么过滤 emoji表情符号呢? 下面是剔除表情字符串的代码片段 python3.6下测试

import redef re_emojis(text):emoji_pattern = pile("["u"\U0001F600-\U0001F64F"u"\U0001F300-\U0001F5FF"u"\U0001F680-\U0001F6FF"u"\U0001F1E0-\U0001F1FF""]+", flags=re.UNICODE)return emoji_pattern.sub(r' ', text)text = 'Lamo see this edit guys?Hi guyhttp://ssoo ://gere comes one more video? Enjoy ♥️'print('init:', text)result = re_emojis(text)print(result)

init: Lamo see this edit guys?Hi guyhttp://ssoo ://gere comes one more video? Enjoy ♥️Lamo see this edit guys Hi guyhttp://ssoo ://gere comes one more video? Enjoy ♥️

这里根据 unicode 范围来删除表情符号,通用的和IOS中的,不是很全,也没找到非常全的list。后面证实还是有写过滤不掉

使用emoji库过滤

终端安装emoji包

pip3 install emoji

借用emoji过滤特殊表情

import emojiimport retext = emoji.demojize('Lamo see this edit guys?Hi guyhttp://ssoo ://gere comes one more video? Enjoy the song Its just for fun guys dont take it far serious?Comment down your views and comment? down for my next video♥️')result = re.sub(':\S+?:', ' ', text)print(result)

Lamo see this edit guys Hi guyhttp://ssoo ://gere comes one more video Enjoy the song Its just for fun guys dont take it far serious Comment down your views and comment down for my next video ️

这样就过滤的超级干净了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。