tregex
tregex is a wrapper around Python regular expressions that makes usage smoother and more user friendly.
Install
pip install tregex-tobiasli
Usage
import tregex as tr
t = tr.to_tuple(pattern='([^;]+?)@(.+?)\.([^;]+)', string='john.smith@somewhere.co.uk; hackzor@coolface.com')
assert t[0][1] == 'somewhere'
assert t[1][2] == 'com'
pattern = '(?P<name>[^;]+?)@(?P<address>.+?)\.(?P<domain>[^;]+)'
t = tr.to_dict(pattern=pattern, string='john.smith@somewhere.co.uk; hackzor@coolface.com')
assert t[0]['name'] == 'john.smith'
assert t[1]['address'] == 'coolface'
t = tr.to_object(pattern=pattern, string='john.smith@somewhere.co.uk; hackzor@coolface.com')
assert t[0].name == 'john.smith'
assert t[1].address == 'coolface'
The above methods patterns can be either a string or a compiled regular expression. TregexCompiled is a class for simply
containing the compiled regex to be run on the above methods. If patterns are long, this usage will speed things up
considerably.
from tregex import TregexCompiled
pattern = '(?P<name>[^;]+?)@(?P<address>.+?)\.(?P<domain>[^;]+)'
trc = TregexCompiled(pattern)
t = trc.to_object('john.smith@somewhere.co.uk; hackzor@coolface.com')
assert t[0].name == 'john.smith'
tregex also contains some methods for simply fuzzy text matching using difflib.SequenceMatcher:
from tregex import find_best
places_in_wales = ['Llanaber', 'Llanaelhaearn', 'Llanbedr', 'Llandbedrgoch', 'Llanbedrog', 'Llanberis', 'Llandanwg', 'Llanegryn', 'Llandegwning', 'Llandeiniolen', 'Llandwrog']
best = find_best('Llanberris', places_in_wales)
assert best == 'Llanberis'
The other methods are find, find_scores (returns the matched scores along with the candidate) and similarity (which
returns the score between a single pair of strings).
Metadata
Release files for tregex-tobiasli 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tregex-tobiasli-1.0.3.tar.gz | 4.9 kB | Without provenance | Details |
Release files / tregex-tobiasli-1.0.3.tar.gz
| Download URL | tregex-tobiasli-1.0.3.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5dcbf38aa42b1154f724fb63f540e3d26c06c01b94240543ca42d6e4866f0eb
|
|
BLAKE2b-256 checksum How to use checksums |
0ee1f60fb772a6e2a30977a69567a594268fae2f06b2f29f0ed0d2d1e99675af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.1
|
Security for tregex-tobiasli 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.