【问题标题】:Python regex '\s' does not match unicode BOM (U+FEFF)Python regex '\s' 与 unicode BOM (U+FEFF) 不匹配
【发布时间】:2015-12-07 00:36:59
【问题描述】:

Python re 模块的 documentation 表示,当设置 re.UNICODE 标志时,'\s' 将匹配:

在 Unicode 字符属性数据库中归类为空格的任何内容。

据我所知,BOM (U+FEFF) 是classified as a space

但是:

re.match(u'\s', u'\ufeff', re.UNICODE)

评估为None

这是 Python 中的错误还是我遗漏了什么?

【问题讨论】:

    标签: python regex unicode


    【解决方案1】:

    根据 unicode 数据库,U+FEFF 不是空白字符。

    维基百科仅将其列为“相关字符”。这些类似于空白字符,但在数据库中没有WSpace 属性。

    \s 不匹配这些字符。

    【讨论】:

    • len([c for c in map(chr, range(sys.maxunicode + 1)) if unicodedata.category(c) == 'Cf' and c.isspace()]) 为零。
    猜你喜欢
    • 1970-01-01
    • 2022-01-19
    • 2019-06-24
    • 2020-01-28
    • 2019-07-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    相关资源
    最近更新 更多