Files
Python_CookBook_repo/2.字符串和文本/10.用正则处理unicode.py
2025-09-10 16:12:45 +08:00

12 lines
460 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
if __name__ == '__main__':
# 默认情况下re模块已经认识了某些unicode字符比如\d现在已经可以匹配unicode的数字
num = re.compile(r'\d+')
# match会从第一个字符开始匹配如果不匹配就返回None
print(num.match('123'))
print(num.match('\u0661\u0662\u0663'))
# 我的评价是别这样干在处理东西之前先将输入标准化为ascii编码是一个程序员的基本素养