psutil 模块

regex 库

在Python中,处理Unicode和正则表达式混合使用时,可以使用 regex 库来增强功能并简化操作。

这是标准库 re 的增强版,提供更全面的 Unicode 支持,包括:

  • 更强大的Unicode属性匹配(如 \p{Script=Han} 匹配所有汉字)。
  • 更好的大小写不敏感匹配(支持Unicode大小写转换)。
  • 模糊匹配(近似字符串匹配)等高级功能75。
import regex
pattern = regex.compile(r'\p{Script=Han}+')  # 匹配所有中文字符
print(pattern.findall("你好,世界!"))  # 输出: ['你好', '世界']