Skip to content

Build a trie-structured regular expression from a list of words

License

Notifications You must be signed in to change notification settings

ZhukovAlexander/triegex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

triegex

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 triegex

Alternatively, you can install the latest release directly from git:

pip install git+https://github.com/ZhukovAlexander/[email protected]

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

About

Build a trie-structured regular expression from a list of words

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages