您当前的位置: 首页 >  Python

浪荡子爱自由

暂无认证

  • 5浏览

    0关注

    72博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Python】python 过滤特殊字符

浪荡子爱自由 发布时间:2022-01-27 14:47:51 ,浏览量:5

Python语言剔除除中英文及数字外的其他任何字符,可以通过正则表达式模块re把非中英文及数字的所有字符串删除,参考实现程序如下:

import re
# 通过re过滤除中英文及数字以外的其他字符
def filter_string(des_string, re_string=''):
    res = re.compile("[^\\u4e00-\\u9fa5^a-z^A-Z^0-9]")
    return res.sub(re_string, des_string)

参考资料

【1】https://zhuanlan.zhihu.com/p/144216817

关注
打赏
1646928109
查看更多评论
立即登录/注册

微信扫码登录

0.0489s