Skip to main content

🔍 HRegex – A Pythonic Human-Readable Regex Builder

PyPI Version Build License
Issues
Stars

HRegex is a Python version of the human-regex project, designed to simplify regex creation using an intuitive, chainable API. This allows developers to write cleaner, more readable regular expressions without dealing with cryptic syntax.


✨ Features

✅ Human-Readable API – No more regex headaches!
✅ Fluent Method Chaining – Build patterns step by step.
✅ Predefined Ranges & Quantifiers – Easily match letters, digits, symbols, and more.
✅ Unicode Support – Handle multilingual characters effortlessly.
✅ Advanced Flags & Groups – Apply regex modifiers and groups with ease.


📦 Installation

⏳ Install via pip

pip install hregex

🛠 Manual Installation

git clone https://github.com/farhaanaliii/hregex.git
cd hregex
python setup.py install

🚀 Quick Start

🔢 Match Digits and Special Characters

from hregex import HRegex  

pattern = HRegex().has_digit().has_special_character().to_regexp()  
match = pattern.match("Hello@123")  

print(bool(match))  # True

📧 Validate Email

pattern = HRegex().word().one_or_more().literal("@").word().one_or_more().literal(".").word().one_or_more().to_regexp()  

print(bool(pattern.match("user@example.com")))  # True
print(bool(pattern.match("invalid-email")))  # False

🛠 API Reference

📌 Character Classes

Method Description
.digit() Matches any digit (\d).
.word() Matches any word character (\w).
.whitespace() Matches whitespace (\s).
.non_whitespace() Matches non-whitespace (\S).
.letter() Matches any letter (A-Z, a-z).
.any_character() Matches any character (.).

📌 Quantifiers

Method Description
.optional() Matches 0 or 1 occurrence (?).
.one_or_more() Matches 1 or more occurrences (+).
.zero_or_more() Matches 0 or more occurrences (*).
.exactly(n) Matches exactly n times ({n}).
.at_least(n) Matches n or more times ({n,}).
.at_most(n) Matches up to n times ({0,n}).
.between(min, max) Matches between min and max times ({min,max}).

📌 Grouping & Anchors

Method Description
.start_group() Starts a non-capturing group ((?: ... )).
.start_capture_group() Starts a capturing group (( ... )).
.end_group() Closes a group ()).
.start_named_group(name) Starts a named capturing group ((?P<name> ... )).
.start_anchor() Matches the start of a string (^).
.end_anchor() Matches the end of a string ($).

📌 Flags

Method Description
.global_() Enables global matching (g).
.non_sensitive() Case-insensitive matching (i).
.multiline() Multi-line mode (m).
.dot_all() Allows . to match newlines (s).
.unicode_digit() Matches Unicode digits (\p{N}).
.unicode_punctuation() Matches Unicode punctuation (\p{P}).
.unicode_symbol() Matches Unicode symbols (\p{S}).

🧪 Running Tests

Run the test suite using:

python -m unittest discover -s tests

📜 License

This project is licensed under the Apache License.


🤝 Contributing

Contributions are welcome! Feel free to:

  • Open an issue for bug reports or feature requests.
  • Submit a pull request with improvements.

⭐ Show Your Support

If you like this project, please consider starring ⭐ it on GitHub!

Stars

Metadata

Release files for hregex 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hregex 1.0.1
File Size Uploaded
hregex-1.0.1.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hregex 1.0.1
File Interpreter ABI Platform
hregex-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / hregex-1.0.1.tar.gz

Download URL hregex-1.0.1.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d27a1c836164c06a9f08c1eaa4686091d262c8b57bf5fc2b24a092d6f568e612
BLAKE2b-256 checksum
How to use checksums
226bac00688b806316b714c2790efde3d97bac776a50abf484e9b3a85ae0cb65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 29, 2025.

Transparency log

Release files / hregex-1.0.1-py3-none-any.whl

Download URL hregex-1.0.1-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f10c023454b5f6495e5be0cf6cf9c090b265cbe3d276129fe85f860411ba8bfb
BLAKE2b-256 checksum
How to use checksums
017fc9f030884c7ac2af9f73cc8ef0a17e083eda666e318f4f01e083b4b941d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 29, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page