Skip to main content

Pre-built, tested regex patterns for common data formats.

Project description

philiprehberger-regex-kit

Tests PyPI version Last updated

Pre-built, tested regex patterns for common data formats.

Installation

pip install philiprehberger-regex-kit

Usage

from philiprehberger_regex_kit import patterns, extract, is_match

# Use compiled patterns directly
if patterns.EMAIL.fullmatch("user@example.com"):
    print("Valid email")

# Quick validation by name
is_match("ip_v4", "192.168.1.1")  # True
is_match("uuid", "not-a-uuid")    # False

Extracting Matches

from philiprehberger_regex_kit import extract

text = "Contact alice@example.com or visit https://example.com"

extract.emails(text)  # ["alice@example.com"]
extract.urls(text)    # ["https://example.com"]

Available Patterns

from philiprehberger_regex_kit import patterns

patterns.EMAIL        # Email addresses
patterns.URL          # HTTP/HTTPS URLs
patterns.IP_V4        # IPv4 addresses
patterns.IP_V6        # IPv6 addresses (full form)
patterns.PHONE        # Phone numbers
patterns.UUID         # UUIDs
patterns.HEX_COLOR    # Hex color codes (#fff, #ff00aa)
patterns.DATE_ISO     # ISO dates (YYYY-MM-DD)
patterns.TIME_24H     # 24-hour time (HH:MM or HH:MM:SS)
patterns.CREDIT_CARD  # Credit card numbers
patterns.MAC_ADDRESS  # MAC addresses
patterns.DOMAIN       # Domain names

API

patterns

Attribute Description
patterns.EMAIL Compiled pattern for email addresses
patterns.URL Compiled pattern for HTTP/HTTPS URLs
patterns.IP_V4 Compiled pattern for IPv4 addresses
patterns.IP_V6 Compiled pattern for IPv6 addresses
patterns.PHONE Compiled pattern for phone numbers
patterns.UUID Compiled pattern for UUIDs
patterns.HEX_COLOR Compiled pattern for hex color codes
patterns.DATE_ISO Compiled pattern for ISO 8601 dates
patterns.TIME_24H Compiled pattern for 24-hour time
patterns.CREDIT_CARD Compiled pattern for credit card numbers
patterns.MAC_ADDRESS Compiled pattern for MAC addresses
patterns.DOMAIN Compiled pattern for domain names

extract

Method Description
extract.emails(text) Extract all email addresses
extract.urls(text) Extract all URLs
extract.phones(text) Extract all phone numbers
extract.ips(text) Extract all IPv4 addresses
extract.uuids(text) Extract all UUIDs

is_match(pattern_name, value)

Parameter Description
pattern_name Pattern name string (e.g. "email", "ip_v4", "uuid")
value The string to validate
Returns bool — True if the entire value matches

Development

pip install -e .
python -m pytest tests/ -v

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

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

philiprehberger_regex_kit-0.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_regex_kit-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_regex_kit-0.2.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_regex_kit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fa196194ede508f54053c6a00fa78a2d7a268a0d92842fba32bb87149c6583fb
MD5 ec7738676338db1fec6b63ed4f74cee5
BLAKE2b-256 37af3709513c1f11ba1c40a52c580351350cba3fac4a5701f111c5fae13116e9

See more details on using hashes here.

File details

Details for the file philiprehberger_regex_kit-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_regex_kit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9783426f7200306dd3ad5a3d29e4892793d8b2c6648114cc82cd3b1cabbcfc2
MD5 c8749723921390ec627a39d72e3f3532
BLAKE2b-256 a00508182af5f1a2f06e696569cb48fe3dce01b5c342a2b1a93637cbd8131dc3

See more details on using hashes here.

Supported by

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