Trie-ized regular expressions in python
Project description
*******
triegex
*******
.. image:: https://travis-ci.org/ZhukovAlexander/triegex.svg?branch=master
:target: https://travis-ci.org/ZhukovAlexander/triegex
About
######
**triegex** is a library that builds a compact trie-structured regular expressions from a list of words.
Installation
########
.. code-block:: bash
pip install triegex
Example usage
########
.. code-block:: python
>>> import triegex
>>>
>>> t = triegex.Triegex('foo', 'bar', 'baz')
>>>
>>> t.to_regex() # build regular expression
'(?:ba(?:r\\b|z\\b)|foo\\b|~^(?#match nothing))'
>>>
>>> t.add('spam')
>>>
>>> 'spam' in t # you check if the word is in there
True
>>>
>>> import re
>>> re.findall(t.to_regex(), 'spam & eggs') # ['spam']
['spam']
Why?
####
The library was inspired by a need to match a list of valid IANA top-level domain names (`which is pretty big <http://data.iana.org/TLD/tlds-alpha-by-domain.txt>`_).
Also it's fun
**triegex** was influenced by these projects: `frak <https://github.com/noprompt/frak>`_, `regex-trie <https://github.com/alexeld/regex-trie>`_ and `Regexp-Trie <http://search.cpan.org/~dankogai/Regexp-Trie-0.02/lib/Regexp/Trie.pm>`_
triegex
*******
.. image:: https://travis-ci.org/ZhukovAlexander/triegex.svg?branch=master
:target: https://travis-ci.org/ZhukovAlexander/triegex
About
######
**triegex** is a library that builds a compact trie-structured regular expressions from a list of words.
Installation
########
.. code-block:: bash
pip install triegex
Example usage
########
.. code-block:: python
>>> import triegex
>>>
>>> t = triegex.Triegex('foo', 'bar', 'baz')
>>>
>>> t.to_regex() # build regular expression
'(?:ba(?:r\\b|z\\b)|foo\\b|~^(?#match nothing))'
>>>
>>> t.add('spam')
>>>
>>> 'spam' in t # you check if the word is in there
True
>>>
>>> import re
>>> re.findall(t.to_regex(), 'spam & eggs') # ['spam']
['spam']
Why?
####
The library was inspired by a need to match a list of valid IANA top-level domain names (`which is pretty big <http://data.iana.org/TLD/tlds-alpha-by-domain.txt>`_).
Also it's fun
**triegex** was influenced by these projects: `frak <https://github.com/noprompt/frak>`_, `regex-trie <https://github.com/alexeld/regex-trie>`_ and `Regexp-Trie <http://search.cpan.org/~dankogai/Regexp-Trie-0.02/lib/Regexp/Trie.pm>`_
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
triegex-0.0.3.tar.gz
(5.0 kB
view details)
File details
Details for the file triegex-0.0.3.tar.gz
.
File metadata
- Download URL: triegex-0.0.3.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc4a9180a0b4da1319ad770a6699ff2c2bfb795532ebb95b8f72dfe75ab33410 |
|
MD5 | 9d83e65e3691f833e2162382eddbfe97 |
|
BLAKE2b-256 | 1d2da119369e86074d0fef12b788fb8a40683072784bec17e0e79c21e6614b3e |