Regex pattern matching and extraction library for Python.
Project description
pattex
A Python library for extracting common patterns from text using regex — emails, URLs, phone numbers, IP addresses, and more.
Installation
pip install pattex
Changelog
[0.4.0] - 2026-05-16
Added
url_extractor.py
extract_urls_by_scheme(text, scheme)— filter URLs by a specific schemeextract_urls_by_domain(text, domain, include_subdomains)— filter URLs by domain, with optional subdomain matchingextract_urls_by_tld(text, tld)— filter URLs by TLD, leading dot optionalextract_secure_urls(text)— returns only https, ftps, sftp, wss URLsextract_insecure_urls(text)— returns only http, ftp, ws URLsextract_urls_with_auth(text)— returns only URLs containing userinfo (user:pass@host)extract_urls_with_port(text, port)— returns URLs with any port, or a specific portextract_unique_domains(text, root_only)— unique hostnames or root domains across all URLsis_url(text, strict)— validates whether a string is a valid URLallow_ipv4,allow_ipv6,allow_port,allow_tail,schemesparameters added toextract_urls_build_strict_regex()— dynamic regex builder withlru_cache(maxsize=16)_build_permissive_regex()— single combined permissive regex with named groups,lru_cache(maxsize=1)
ip_extractor.py ← new file
extract_ip_urls(text, ipv4, ipv6)— extract URLs whose host is an IP addressextract_localhost_urls(text, allow_port, allow_tail)— extract localhost URLs only
regexes.py
_SCHEMES— raw scheme alternation string_BARE_DOMAIN— raw bare domain pattern without port/tail
_utils.py
_get_root_domain(host)— extracts root domain from hostnamehas_auth(url)— checks whether a URL contains userinfo_is_ip_host(url)— checks whether a URL host is an IP address
extractor_constants.py
URL_SCHEMES—Literaltype for all supported schemes
Changed
include_localhostrenamed toallow_localhost— breaking change- Permissive mode now runs a single
finditerscan instead of 3–4 separate loops — protocol-relative, bare domain, bare IP, and localhost combined into one regex via named groups ((?P<name>...)) match.lastgroupused to dispatch per-branch guard logic in permissive loop- Localhost always included in permissive mode implicitly —
allow_localhostonly controls strict mode _build_permissive_regextakes no arguments — localhost always included in permissive- Schemed
http://localhostalways extracted in strict mode regardless ofallow_localhost extract_secure_urlsandextract_insecure_urlshave nomodeparameter — scheme implies strictness
Internal
- All raw pattern constants kept as plain strings in
regexes.py— compiled only at assembly time lru_cacheon both builders avoids recompilation on repeated calls with same flagsurlparseimport consolidated at top ofurl_extractor.py- Walrus operator used in
extract_urls_with_portto avoid doubleurlparsecall
v0.3.1 - 2026-05-13
Fixed
- Zoho extractor: removed hyphen (
-) and plus (+) from allowed local part characters — Zoho usernames only permit letters, numbers, dots, and underscores per official documentation - Zoho extractor:
+is a subaddressing tag separator, not a valid account creation character; removed from base regex and validation logic - Proton extractor: tightened leading/trailing character rule — local part must
begin and end with an alphanumeric character (was checking against
._-set, now explicitly usesisalnum()to match Proton's documented rule)
Changed
- Renamed
email_extraction.py→email_extractor.py - Renamed
urls_extraction.py→url_extractor.py - Updated docstrings for
extract_zoho_emailsandextract_proton_emailsto reflect corrected provider rules - Added inline comments on each validation rule inside
email_extractor.pyfor all six provider extractors - Added documentation comments for all email regex patterns in
constants/regexes.pyand corresponding.pyistubs
Internal
- General code cleanups across extractor modules
Status
Currently under active development. Full documentation and usage examples coming soon.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pattex-0.4.0.tar.gz.
File metadata
- Download URL: pattex-0.4.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac4daee99a67494bdb6dc75f3fd9e167adb3c95bda54ed113acdc9e9d67e55a4
|
|
| MD5 |
8d11a24c05ce48f101eb67400fc59838
|
|
| BLAKE2b-256 |
1bb59cb61b612f38782b869d17da8e0492bf81d741c1630e7c388f2d9824a149
|
File details
Details for the file pattex-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pattex-0.4.0-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca40c139b5fdc436aadc791f7df584e9c587d47b60d0196b454c8470babd6c30
|
|
| MD5 |
b9efc8dea4e44aa8bbeef95ad3418491
|
|
| BLAKE2b-256 |
0f36d892b8ca0407bec5b46ce45f2006bf56533732884db548476f04de69010e
|