【问题标题】:how to use re.sub in python to remove a character by it's unicode [duplicate]如何在python中使用re.sub通过它的unicode删除一个字符[重复]
【发布时间】:2020-09-17 18:53:38
【问题描述】:

例如我想做的事

new_data = t = re.sub('[ufd3e]'),' ',new_data)

替换字符 uf3ef 但不起作用

【问题讨论】:

  • 你试过reading the documentation吗?
  • Python 默认接受 utf-8。您可能只需将'[﴾]' 放入您的代码中。
  • \ufd3e 有效,但当您只有一个字符时,不需要方括号,这意味着“选择一个”。就此而言,根本不需要正则表达式。只需使用new_data = new_data.replace('\ufd3e',' ')

标签: python string unicode


【解决方案1】:

您需要使用\u 来告诉它是 unicode(并且您的右括号放错了位置)

new_data = t = re.sub(u'[\ufd3e]',' ',new_data)

【讨论】:

    猜你喜欢
    • 2016-08-30
    • 2021-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 2013-11-25
    • 1970-01-01
    相关资源
    最近更新 更多