Skip to main content

HRegex designed to simplify regex creation

Project description

🔍 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

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

hregex-1.0.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

hregex-1.0.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

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

Hashes for hregex-1.0.0.tar.gz
Algorithm Hash digest
SHA256 874ea483d6e6ba5c096333e6be29e03f5a021b0a29de0f1c1215614e04527d30
MD5 22bbfe70c45df1ebef53ac08cbd0c926
BLAKE2b-256 9cdca5694106581673d12a939b3d6b6167d19472b61e23d33f4e4342b2c7e49a

See more details on using hashes here.

Provenance

The following attestation bundles were made for hregex-1.0.0.tar.gz:

Publisher: workflow.yml on farhaanaliii/hregex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for hregex-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 477447c1e37b7c09e354e6b0af3cb95bd5959f4734366a03208da2c462a6b436
MD5 e17cba7230b9b6fdcbfe6f8e5d7dfd40
BLAKE2b-256 30aef385f879c28f19d62a0830ed6f2a12f1c329ffe321e4eaa5af7aad86084e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hregex-1.0.0-py3-none-any.whl:

Publisher: workflow.yml on farhaanaliii/hregex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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