Efficient string matching with regular expressions
This package includes a pure Python function that enables you to represent a set of strings as a regular expression. With this regular expression, you can perform various operations, such as replacing, extracting and matching keywords. The name of the package comes from the internal trie used to build the regular expression (TRie to REgeX)
Install trrex
Use pip,
pip install trrex
Usage
import trrex as tx
import re
pattern = tx.make(['baby', 'bat', 'bad'])
hits = re.findall(pattern, 'The baby was scared by the bad bat.')
# hits = ['baby', 'bat', 'bad']
pandas
import trrex as tx
import pandas as pd
frame = pd.DataFrame({
"txt": ["The baby", "The bat"]
})
pattern = tx.make(['baby', 'bat', 'bad'], prefix=r"\b(", suffix=r")\b") # need to specify capturing groups
frame["match"] = frame["txt"].str.extract(pattern)
hits = frame["match"].tolist()
print(hits)
# hits = ['baby', 'bad']
Why use trrex?
- trrex builds a better regex pattern, than the simple regex union, therefore searching (and replacing) strings is about 300 times faster than a regex union pattern, and about 2.5 times faster than FlashText algorithm. See below for a performance comparison:
- Plays well with others, can be integrated easily with pandas, spacy and any other regex engine. See the documentation for examples.
- Pure Python, no other dependencies
Issues
If you have any issues with this repository, please don't hesitate to raise them. It is actively maintained, and we will do our best to help you.
Acknowledgments
This project is based on the following resources:
Liked the work?
If you've found this repository helpful, why not give it a star? It's an easy way to show your appreciation and support for the project. Plus, it helps others discover it too!
Metadata
Release files for trrex 0.0.7
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 | Actions |
|---|---|---|---|---|
| trrex-0.0.7.tar.gz | 195.9 kB | Without provenance | Details for trrex-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trrex-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for trrex-0.0.7-py3-none-any.whl |
Total release size: 203.4 kB
Release files / trrex-0.0.7.tar.gz
| Download URL | trrex-0.0.7.tar.gz |
|---|---|
| Size | 195.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22eeee67cde87ff178b61e5ee2607b2ae5cc694f0b3e6eabd0158f4d8389e6a8
|
|
BLAKE2b-256 checksum How to use checksums |
b285780675f83e6e07d8f4ab037ee9db2c981d3ab7da160b9bffafa9130bfc4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.0
|
Release files / trrex-0.0.7-py3-none-any.whl
| Download URL | trrex-0.0.7-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f20144dfe549d2b64add8b24e681895d6ebe10d17f27d15f4cdfa212186ff47
|
|
BLAKE2b-256 checksum How to use checksums |
d4b3097b58de339af08d12d5e2b5c73ca33684e91be3d8a32428ea23d557d776
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.0
|
Security for trrex 0.0.7
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.