Skip to main content

Transform set of words to efficient regular expression

Project description

trrex logo
 
Trrex Downloads PyPI Version Package Status Code Coverage Status Documentation Status

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:

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!

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

trrex-0.0.6.tar.gz (138.3 kB view details)

Uploaded Source

Built Distribution

trrex-0.0.6-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file trrex-0.0.6.tar.gz.

File metadata

  • Download URL: trrex-0.0.6.tar.gz
  • Upload date:
  • Size: 138.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.13

File hashes

Hashes for trrex-0.0.6.tar.gz
Algorithm Hash digest
SHA256 95eaecee76449acfc588bae73f32ad3ce5a7a458bac5c46089b65fa78370ff2a
MD5 db9dae77c4798ae9b040e3a13e802f11
BLAKE2b-256 f2d3bf660974bf7c45e8eea26f2b081523296cc9983b8e2b7526057291bafed2

See more details on using hashes here.

File details

Details for the file trrex-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: trrex-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.13

File hashes

Hashes for trrex-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 dee48cbb02722ddeba2f77febbfaf1b90a687fa392cf8449e186da54079bdce1
MD5 54a687ea34c82a4b3a2e20fe527671b8
BLAKE2b-256 587d70197a996358bf9939cb02ec52260fb7cf8870a4f6be59d094b59db71e96

See more details on using hashes here.

Supported by

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