A tool to generate semi-minimized regular expression alternations.
Project description
Triex
A tool to generate semi-minimized regular expression alternations.
Given a list of str
, int
, and float
values, triex constructs a trie data structure and generates a minimized regular expression that matches all members in the trie. The regex is created walking the values left-to-right, so the best results are achieved with values that share a common prefix.
Requirements
- Python 3.10.x, 3.11.x
Installation
pip install py-triex
Usage
As a Library
>>> from triex import Trie
>>> t = Trie(['foo', 'foobar', 'foobaz', 'bar', 'bat'])
>>> t.to_regex()
ba[rt]|foo(?:ba[rz])?
Command Line
Usage: triex [OPTIONS] COMMAND [ARGS]...
A tool to generate semi-minimized regular expression alternations.
Options:
--help Show this message and exit.
-v, --verbose Increase verbosity.
--version Show the version and exit.
Commands:
batch Batch convert file contents to patterns.
convert Convert input to a regex pattern.
Examples
Convert:
$ echo "foo\nfoobar\nfoobaz\nbar\nbat" > words.txt
$ triex convert -i words.txt
ba[rt]|foo(?:ba[rz])?
$ echo -e "foo\nfoobar\nfoobaz\nbar\nbat" | triex convert
ba[rt]|foo(?:ba[rz])?
Batch:
$ printf "foo\nbar" > words1.txt
$ printf "foo\nbaz" > words2.txt
$ triex batch *.txt
Converting words1.txt
Converting words2.txt
$ less -FX words1.txt
bar|foo
$ less -FX words2.txt
baz|foo
License
triex is released under the MIT License
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
py_triex-2.0.6.tar.gz
(6.3 kB
view details)
Built Distribution
File details
Details for the file py_triex-2.0.6.tar.gz
.
File metadata
- Download URL: py_triex-2.0.6.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f6550042e7388459d974cbc2ceb7cd7ac01563fe3c94b7c8ae93b85233fc0f3 |
|
MD5 | 9076716dcf92ab20b98a2e09dc0e0e8c |
|
BLAKE2b-256 | eb01057581e35231726ad492a82654ca839b950f03d3131395583a33ca36a924 |
File details
Details for the file py_triex-2.0.6-py3-none-any.whl
.
File metadata
- Download URL: py_triex-2.0.6-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d1a0b7777e018bac873ed22fea0290f130ce33ac86945e66e4e75fded550bce |
|
MD5 | 3f2cfaea894f9328b2866cfa12999226 |
|
BLAKE2b-256 | 69b58acd249ba358751b9287466d0e5a529b8f4825bcf63e8ff07350d04d9f9f |