在正则式中使用Unicode-python cookbook(第3版)高清中文完整版

时间:2024-06-29 23:05:53
【文件属性】:

文件名称:在正则式中使用Unicode-python cookbook(第3版)高清中文完整版

文件大小:4.84MB

文件格式:PDF

更新时间:2024-06-29 23:05:53

python cookbook 第3版 高清 中文完整版

2.10 在正则式中使用Unicode 问题 你正在使用正则表达式处理文本,但是关注的是Unicode字符处理。 解决方案 默认情况下 re 模块已经对一些Unicode字符类有了基本的支持。 比如, \\d 已经匹配 任意的unicode数字字符了: >>> import re >>> num = re.compile('\d+') >>> # ASCII digits >>> num.match('123') <_sre.SRE_Match object at 0x1007d9ed0> >>> # Arabic digits >>> num.match('\u0661\u0662\u0663') <_sre.SRE_Match object at 0x101234030> >>> 如果你想在模式中包含指定的Unicode字符,你可以使用Unicode字符对应的转义序列(比 如 \uFFF 或者 \UFFFFFFF )。 比如,下面是一个匹配几个不同阿拉伯编码页面中所有字符 的正则表达式: >>> arabic = re.compile('[\u0600-\u06ff\u0750-\u077f\u08a0-\u08ff]+') >>>


网友评论