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

? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ✊
✊ ✊ ✊ ✊ ✊ ✊ ✊ ✊

过滤方法

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

import re
def re_emojis(text):
    emoji_pattern = re.compile("["
           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 emoji
import re
text = 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 ️

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

  • 50
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值