Monkey patch正则表达式
项目描述
# GoRella [](https://travis-ci.org/frostming/gorella)
Monkey patch正则表达式方法到内置字符串类型
## 简介 此项目旨在简化正则表达式的使用,灵感来自JavaScript中的RegExp。名称来自“gorilla”和“re”。单文件模块将在导入时monkey patch以下字符串类型的内置方法
replace
split和rsplit
find和rfind
index和rindex
partition和rpartition
count
startswith和endswith
此外,它通过以下re模块的方法扩展了内置字符串类型
match
search
findall
finditer
## 使用方法 只需在一行中导入gorella,一切都会为你完成:`python >>> import gorella >>> 'I am 26 years old.'.search('\d+').group() '26' ` 对于内置方法,当传递一个正则表达式对象时,它将调用相应的re函数,否则将回退到内置的一个:`python >>> pat = re.compile('\d+') >>> 'I am 26 years old.'.find('am') 2 >>> 'I am 26 years old.'.find(pat) 5 >>> 'I am 26 years old.'.partition(pat) ('I am ', '26', ' years old') ` 因为它用Python方法替换了纯C方法,性能可能会受到影响。
## Python 3 支持 由于猴子补丁高度依赖于 CPython 的 C-API,因此它不支持 CPython 以外的实现。该测试在 Python 2.6、2.7、3.3、3.4 和 3.5 上通过。
## 许可证 MIT
项目详情
gorella-0.1.0-revision.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 40bed43c7d30ab5138873775b043440c1c7693afc0a5959225b4c4dee94ad66e |
|
MD5 | eb1a47991cc32ebeeb3c262a2a137f02 |
|
BLAKE2b-256 | 6446965e568037f16c224f05f2e3b88591dfa02fb96633e36beb7f8590b6ed01 |