HRegex designed to simplify regex creation
Project description
🔍 HRegex – A Pythonic Human-Readable Regex Builder
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!
Project details
Release history Release notifications | RSS feed
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 hregex-1.0.0.tar.gz.
File metadata
- Download URL: hregex-1.0.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
874ea483d6e6ba5c096333e6be29e03f5a021b0a29de0f1c1215614e04527d30
|
|
| MD5 |
22bbfe70c45df1ebef53ac08cbd0c926
|
|
| BLAKE2b-256 |
9cdca5694106581673d12a939b3d6b6167d19472b61e23d33f4e4342b2c7e49a
|
Provenance
The following attestation bundles were made for hregex-1.0.0.tar.gz:
Publisher:
workflow.yml on farhaanaliii/hregex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hregex-1.0.0.tar.gz -
Subject digest:
874ea483d6e6ba5c096333e6be29e03f5a021b0a29de0f1c1215614e04527d30 - Sigstore transparency entry: 189682849
- Sigstore integration time:
-
Permalink:
farhaanaliii/hregex@e1bce9e335600435fd72d6e2b3345527ea8f3c30 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/farhaanaliii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@e1bce9e335600435fd72d6e2b3345527ea8f3c30 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hregex-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hregex-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
477447c1e37b7c09e354e6b0af3cb95bd5959f4734366a03208da2c462a6b436
|
|
| MD5 |
e17cba7230b9b6fdcbfe6f8e5d7dfd40
|
|
| BLAKE2b-256 |
30aef385f879c28f19d62a0830ed6f2a12f1c329ffe321e4eaa5af7aad86084e
|
Provenance
The following attestation bundles were made for hregex-1.0.0-py3-none-any.whl:
Publisher:
workflow.yml on farhaanaliii/hregex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hregex-1.0.0-py3-none-any.whl -
Subject digest:
477447c1e37b7c09e354e6b0af3cb95bd5959f4734366a03208da2c462a6b436 - Sigstore transparency entry: 189682851
- Sigstore integration time:
-
Permalink:
farhaanaliii/hregex@e1bce9e335600435fd72d6e2b3345527ea8f3c30 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/farhaanaliii
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@e1bce9e335600435fd72d6e2b3345527ea8f3c30 -
Trigger Event:
release
-
Statement type: