Skip to main content

Trie-ized regular expressions in python

Project description

https://travis-ci.org/ZhukovAlexander/triegex.svg?branch=master

About

triegex is a library that builds a compact trie-structured regular expressions from a list of words.

Installation

pip install git+https://github.com/ZhukovAlexander/triegex.git

Example usage

>>> 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).

Also it’s fun

triegex was influenced by these projects: frak, regex-trie and Regexp-Trie

Project details


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.2.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file triegex-0.0.2.tar.gz.

File metadata

  • Download URL: triegex-0.0.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for triegex-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e1cbe3322b1e7023c65e157df23694f7898792c8cab9ac5514f7622eb283e011
MD5 3be799b357e208af21d37d7898f8a4ab
BLAKE2b-256 34853735b7f9697057db8b3b2f558f723c7f6f9f61ffb0a14ed47c3c7b8ec464

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page