• Unicode 字符表:https://en.wikibooks.org/wiki...
  • \xa0 是 NO-Break Space,不连续空格
  • \xad 是 Soft Hyphen,软连接符,常被显示为短横或者空格

可打印字符

>>> '你好'.isprintable()
True

>>> '\x41'.isprintable()
True

>>> '\xa0'.isprintable()
False

>>> '\xad'.isprintable()
False

>>> '\u0041'.isprintable()
True

UTF8

>>> import codecs
>>> utf8_decoder = codecs.getincrementaldecoder('utf8')()
>>> utf8_decoder.decode(b'hello')
'hello'

>>> utf8_decoder.decode(b'\x41')
'A'

>>> utf8_decoder.decode(b'\xa0')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 0:
 invalid start byte

regex

# Letter
>>> regex.findall(r'[\p{L}]', '水_A_\x41_\xa0_\xad_0\u4dc7地\u20de')
['水', 'A', 'A', '地']
# Mark
>>> regex.findall(r'[\p{M}]', '水_A_\x41_\xa0_\xad_0\u4dc7地\u20de')
['⃞']
# Separator
>>> regex.findall(r'[\p{Z}]', '水_A_\x41_\xa0_\xad_0\u4dc7地\u20de')
['\xa0']
# Symbol
>>> regex.findall(r'[\p{S}]', '水_A_\x41_\xa0_\xad_0\u4dc7地\u20de')
['䷇']
# Number
>>> regex.findall(r'[\p{N}]', '水_A_\x41_\xa0_\xad_0\u4dc7地\u20de')
['0']
# Punctuation
>>> regex.findall(r'[\p{P}]', '水_A_\x41_\xa0_\xad_0\u4dc7地\u20de')
['_', '_', '_', '_', '_']
# Other
>>> regex.findall(r'[\p{C}]', '水_A_\x41_\xa0_\xad_0\u4dc7地\u20de')
['\xad']

pandahouse

  • pandahouse 处理 \xad 之类的非常规字符会有问题
本文出自 qbit snap

qbit
268 声望279 粉丝

引用和评论

0 条评论