跳转到主要内容

Monkey patch正则表达式

项目描述

# GoRella [![Build Status](https://travis-ci.org/frostming/gorella.svg?branch=master)](https://travis-ci.org/frostming/gorella)

Monkey patch正则表达式方法到内置字符串类型

## 简介 此项目旨在简化正则表达式的使用,灵感来自JavaScript中的RegExp。名称来自“gorilla”和“re”。单文件模块将在导入时monkey patch以下字符串类型的内置方法

  • replace

  • splitrsplit

  • findrfind

  • indexrindex

  • partitionrpartition

  • count

  • startswithendswith

此外,它通过以下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 (6.7 kB 查看哈希值)

上传时间