使用cffi访问re2库
cffi_re2的Python项目详细描述
#cffi_re2
[![构建状态](https://travis ci.org/vls/cffi_re2.png)(https://travis ci.org/vls/cffi_re2)
cffi_re2是基于cffi的用于google的[re2]库(https://github.com/google/re2)的高级python绑定。
在ubuntu/debian上,可以使用
``bash
sudo apt get install libre2 dev
```
else,您只需从git存储库安装当前版本:
``bash
git clone https://github.com/google/re2.git
make
make test
sudo make install
```
有关详细信息,请参阅[re2存储库](https://github.com/google/re2)。
您可以安装cffi re2:
```bash
pip install cffi re2
`````
或从本地副本:
``bash
`sudo python setup.py install
````
*cffi re2*与*python3.x*和[*py pypy*](pypypypy.org)(包括*py pypy3*)完全兼容。
您可以使用:
``bash
sudo python setup.py test
````
在几乎所有情况下,您都可以对两个库使用相同的源代码。cffi re2中的标志与re中的标志完全相同,因此可以在cffi re2.compile中使用re.ignorecase,反之亦然。
某些语法元素,如零宽度lookaheads或lookbehinds[不受支持](https://github.com/google/re2/wiki/syntax)。
使用这些语法元素时,后端在调用“cffi-re2.compile”时报告语法错误,例如:
````
valueerror:invalid perl operator:(?<;
```
一种解决方法是将正则表达式转换为组捕获形式,然后选择适当的组。但是,对于更大的复杂正则表达式集,这通常是不可行的。
在这种情况下,建议使用混合方法,即,如果*cffi re2*无法编译表达式,则返回*re*。
``python
``import re
import cffi re2
def compileregex(rgx,flags=0):
尝试:
returncffi re2.compile(rgx,flags)
除了valueerror:
返回re.compile(rgx,flags)
````
注意,在当前的实现中,*cffi re2*和*re*之间仍然存在一些已知和未知的不兼容。如果您遇到问题,请将其作为错误报告。
许多新特性和改进都是由[uli kóhler]贡献的(https://github.com/ulikoehler)。
[![构建状态](https://travis ci.org/vls/cffi_re2.png)(https://travis ci.org/vls/cffi_re2)
cffi_re2是基于cffi的用于google的[re2]库(https://github.com/google/re2)的高级python绑定。
在ubuntu/debian上,可以使用
``bash
sudo apt get install libre2 dev
```
else,您只需从git存储库安装当前版本:
``bash
git clone https://github.com/google/re2.git
make
make test
sudo make install
```
有关详细信息,请参阅[re2存储库](https://github.com/google/re2)。
您可以安装cffi re2:
```bash
pip install cffi re2
`````
或从本地副本:
``bash
`sudo python setup.py install
````
*cffi re2*与*python3.x*和[*py pypy*](pypypypy.org)(包括*py pypy3*)完全兼容。
您可以使用:
``bash
sudo python setup.py test
````
在几乎所有情况下,您都可以对两个库使用相同的源代码。cffi re2中的标志与re中的标志完全相同,因此可以在cffi re2.compile中使用re.ignorecase,反之亦然。
某些语法元素,如零宽度lookaheads或lookbehinds[不受支持](https://github.com/google/re2/wiki/syntax)。
使用这些语法元素时,后端在调用“cffi-re2.compile”时报告语法错误,例如:
````
valueerror:invalid perl operator:(?<;
```
一种解决方法是将正则表达式转换为组捕获形式,然后选择适当的组。但是,对于更大的复杂正则表达式集,这通常是不可行的。
在这种情况下,建议使用混合方法,即,如果*cffi re2*无法编译表达式,则返回*re*。
``python
``import re
import cffi re2
def compileregex(rgx,flags=0):
尝试:
returncffi re2.compile(rgx,flags)
除了valueerror:
返回re.compile(rgx,flags)
````
注意,在当前的实现中,*cffi re2*和*re*之间仍然存在一些已知和未知的不兼容。如果您遇到问题,请将其作为错误报告。
许多新特性和改进都是由[uli kóhler]贡献的(https://github.com/ulikoehler)。