Skip to main content

HRegex: A streamlined approach to simplifying 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.1.tar.gz (9.1 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.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file hregex-1.0.1.tar.gz.

File metadata

  • Download URL: hregex-1.0.1.tar.gz
  • Upload date:
  • Size: 9.1 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.1.tar.gz
Algorithm Hash digest
SHA256 d27a1c836164c06a9f08c1eaa4686091d262c8b57bf5fc2b24a092d6f568e612
MD5 140b83f8e263cc071e68b834297ad698
BLAKE2b-256 226bac00688b806316b714c2790efde3d97bac776a50abf484e9b3a85ae0cb65

See more details on using hashes here.

Provenance

The following attestation bundles were made for hregex-1.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: hregex-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f10c023454b5f6495e5be0cf6cf9c090b265cbe3d276129fe85f860411ba8bfb
MD5 0f67122246d0f3a3fa9b524f75758081
BLAKE2b-256 017fc9f030884c7ac2af9f73cc8ef0a17e083eda666e318f4f01e083b4b941d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for hregex-1.0.1-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