更简单、更干净地访问正则表达式。球也一样。
simplere的Python项目详细描述
python正则表达式(re)字符串的简化接口 搜索。消除步骤并提供对结果的更简单访问。作为奖励, 还提供了访问unix glob搜索的兼容方式。
用法
python正则表达式很强大,但是该语言缺乏 (通过的)作业需要准备 运动,然后测试:
import re match = re.search(pattern, some_string) if match: print match.group(1)
使用simplere,您可以用较少的步骤完成此操作:
from simplere import * if match / re.search(pattern, some_string): print match[1]
在复杂的搜索和操作中尤其有价值 需要多级搜索的代码 前置条件、错误检查和匹配后清理、格式化, 以及行动。
作为奖励, simplere还提供简单的全局访问。:
if 'globtastic' in Glob('glob*'): print "Yes! It is!" else: raise ValueError('OH YES IT IS!')
它还可以方便地匹配多个glob 模式和/或执行不区分大小写的全局搜索。
见Read the Docs 完整的安装和使用文档。