re101
A compendium of commonly-used regular expressions.
This package pertains specifically to regular expressions embedded inside Python and compiled with Python's re module.
Tested on Python 3.10, 3.11, 3.12, 3.13, and 3.14.
Install
uv add re101 # or: pip install re101
Develop
This project uses uv for environment and build
management (uv_build
backend), ruff for lint/format, and
ty for type-checking.
uv sync
uv run pytest
uv run ruff check
uv run ty check
Introduction
All importable objects are compiled regular expressions. For instance, US_PHONENUM matches sequences following the North American Number Plan (NANP) format. In plain English, this is what would qualify as a "North American telephone number":
>>> from re101 import US_PHONENUM
>>> text = """
... Ross McFluff: +1 (834) 345.1254 155 Elm Street
... Ronald Heathmore: 892-345-3428 436 Finley Avenue
... Frank Burger: 541-7625 662 South Dogwood Way
... Heather Albrecht: 5483264584 919 Park Place"""
>>> US_PHONENUM.findall(text)
['+1 (834) 345.1254', '892-345-3428', '541-7625', '5483264584']
Currently, the package supports regexes related to:
- email addresses
- whitespace
- words/tokens
- phone numbers
- IP addresses
- URLs
- integers, decimals, numbers
- geographic information
- personally identifiable information
Naming Conventions
Objects exported by the package may be in either UPPERCASE, CamelCase, or lower_case:
UPPERCASE: These are compiled regular expressions, of typere.Pattern[str], which is the result ofre.compile().CamelCase: These are classes whose__new__()method returns a compiled regular expression, but takes a few additional parameters that add optionality to the compiled result. For instance, theNumberclass lets you allow or disallow leading zeros and commas.lower_case: These are traditional functions built around the package's regex constants. They do not share any consistency in their call syntax or result type.
Disclaimer
Use these regular expressions with care. It is unlikely that any of them cover 100.00% of the cases that they are intended to cover. They are built to handle "99.x%" of cases. With all regular expressions, a balance must be made: covering an incremental 0.1% of cases often requires a large marginal amount of work and code.
If you do notice egregious mistakes or omissions, please consider submitting an issue or pull request.
Please assume these expressions are "US-centric" unless noted otherwise. For instance, the zipcodes expression looks only for XXXXX or XXXXX-XXXX zip codes.
Sources
Citations are included for "unique" regexes that are copied from a singular source. More "generic" regexes that can be found in similar form from multiple public sources may not be cited here.
- Goyvaerts, Jan & Steven Levithan. Regular Expressions Cookbook, 2nd ed. Sebastopol: O'Reilly, 2012.
- Friedl, Jeffrey. Mastering Regular Expressions, 3rd ed. Sebastopol: O'Reilly, 2009.
- Goyvaerts, Jan. Regular Expressions: The Complete Tutorial. https://www.regular-expressions.info/.
- Python.org documentation:
remodule. https://docs.python.org/3/library/re.html - Kuchling, A.M. "Regular Expression HOWTO." https://docs.python.org/3/howto/regex.html
- Python.org documentation:
ipaddressmodule. Copyright 2007 Google Inc. Licensed to PSF under a Contributor Agreement. https://docs.python.org/3/library/ipaddress.html - nerdsrescueme/regex.txt. https://gist.github.com/nerdsrescueme/1237767
To-Do List
These patterns are not currently implemented:
- Dates and times (both ISO-8601 and more informal, such as those that can be parsed by Python's
dateutil) - Money/currency (including both the leading or trailing sign, numbers, and punctuation)
Metadata
Release files for re101 1.0.0
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 |
|---|---|---|---|---|
| re101-1.0.0.tar.gz | 11.7 kB | Without provenance | Details for re101-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| re101-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for re101-1.0.0-py3-none-any.whl |
Total release size: 24.1 kB
Release files / re101-1.0.0.tar.gz
| Download URL | re101-1.0.0.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d38a0987f32f535d6fd530d05bc431ae7e43c4751b60674c2f6990808f58fab
|
|
BLAKE2b-256 checksum How to use checksums |
ef4ac76e3544fd434de8e017d9f5e024df171a058b2468621574f1d59654182f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / re101-1.0.0-py3-none-any.whl
| Download URL | re101-1.0.0-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e87928d909ea34dd25aec8cdba95852d28f941eaa8bb62e977d48cd8bb131a73
|
|
BLAKE2b-256 checksum How to use checksums |
49a5f2d99037747ddd9d4a7d41162f6ccd6d9814991124a13a4c40c0968b3806
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for re101 1.0.0
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.