RegexFactory
Dynamically construct python regex patterns.
Examples
Matching Initials
Say you want a regex pattern to match the initials of someones name.
import re
from regexfactory import Amount, Range
pattern = Amount(Range("A", "Z"), 2, 3)
matches = pattern.findall(
"My initials are BDP. Valorie's are VO"
)
print(matches)
['BDP', 'VO']
Matching Hex Strings
Or how matching both uppercase and lowercase hex strings in a sentence.
import re
from regexfactory import *
pattern = Optional("#") + Or(
Amount(
Set(
Range("0", "9"),
Range("a", "f")
),
6
),
Amount(
Set(
Range("0", "9"),
Range("A", "F")
),
6
),
)
sentence = """
My favorite color is #000000. I also like 5fb8a0. My second favorite color is #FF21FF.
"""
matches = pattern.findall(sentence)
print(matches)
['#000000', '5fb8a0', '#FF21FF']
Matching URLs
Or what if you want to match urls in html content?
from regexfactory import *
protocol = Amount(Range("a", "z"), 1, or_more=True)
host = Amount(Set(WORD, DIGIT, '.'), 1, or_more=True)
port = Optional(IfBehind(":") + Multi(DIGIT))
path = Multi(
RegexPattern('/') + Multi(
NotSet('/', '#', '?', '&', WHITESPACE),
match_zero=True
),
match_zero=True
)
patt = protocol + RegexPattern("://") + host + port + path
sentence = "This is a cool url, https://github.com/GrandMoff100/RegexFactory/ "
print(patt)
print(patt.search(sentence))
[a-z]{1,}://[\w\d.]{1,}(?:\d{1,})?(/([^/#?&\s]{0,})){0,}
<re.Match object; span=(15, 51), match='https://github.com/GrandMoff100/RegexFactory/'>
The Pitch
This library is really good at allowing you to intuitively understand how to construct a regex expression.
It helps you identify what exactly your regular expression is, and can help you debug it.
This is library is also very helpful for generating regex expressions on the fly if you find uses for it.
You can also extend this library by subclassing RegexPattern and add your own support for different regex flavors.
Like generating regex expresison with Perl5 extensions.
There you have it. This library is intuitive, extensible, modular, and dynamic. Why not use it?
Metadata
Release files for RegexFactory 1.0.1
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 |
|---|---|---|---|---|
| regexfactory-1.0.1.tar.gz | 22.7 kB | Without provenance | Details for regexfactory-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| RegexFactory-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for RegexFactory-1.0.1-py3-none-any.whl |
Total release size: 44.7 kB
Release files / regexfactory-1.0.1.tar.gz
| Download URL | regexfactory-1.0.1.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a3bc383f665e3205f5127c07ec8abffdcdff80de170b80319bbab7584cbfd87
|
|
BLAKE2b-256 checksum How to use checksums |
f44d6f7e066227c0baa97a579595a0af71ac3f414da69aec35792d3cceecd2fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / RegexFactory-1.0.1-py3-none-any.whl
| Download URL | RegexFactory-1.0.1-py3-none-any.whl |
|---|---|
| Size | 22.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09d02e8570fb6922b6523dbdd757a261c0570d7b07671efca389663d9f8e5bee
|
|
BLAKE2b-256 checksum How to use checksums |
44d4c9e1f708f741ccf40a7c896c8e58774ddcbe788ffaf0d80b3697d7528b5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for RegexFactory 1.0.1
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.