跳转到主要内容

Python中的Trie-化正则表达式

项目描述

*******
triegex
*******
.. image:: https://travis-ci.org/ZhukovAlexander/triegex.svg?branch=master
:target: https://travis-ci.org/ZhukovAlexander/triegex
关于
######


**triegex**是一个库,可以从单词列表构建紧凑的trie结构正则表达式。

安装
########

.. code-block:: bash

pip install triegex

示例用法
########

.. code-block:: python

>>> import triegex
>>>
>>> t = triegex.Triegex('foo', 'bar', 'baz')
>>>
>>> t.to_regex() # 构建正则表达式
'(?:ba(?:r\\b|z\\b)|foo\\b|~^(?#match nothing))'
>>>
>>> t.add('spam')
>>>
>>> 'spam' in t # 检查单词是否在其中
True
>>>
>>> import re
>>> re.findall(t.to_regex(), 'spam & eggs') # ['spam']
['spam']

为什么?
####
该库受需要匹配IANA顶级域名列表(`这是一个相当大的列表 <http://data.iana.org/TLD/tlds-alpha-by-domain.txt>`_)的需求所启发。

也有趣

**triegex**受以下项目的影响:`frak <https://github.com/noprompt/frak>`_, `regex-trie <https://github.com/alexeld/regex-trie>`_ 和 `Regexp-Trie <http://search.cpan.org/~dankogai/Regexp/Trie-0.02/lib/Regexp/Trie.pm>`_

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

triegex-0.0.3.tar.gz (5.0 kB 查看哈希值)

上传时间 源代码

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面