Skip to main content

Python verbal based regular expressions

Project description

Verbex: Python verbal based regular expressions

Generic badge Code style: black PyPI pyversions Generic badge Generic badge Generic badge Generic badge Dynamic TOML Badge

Installation

pip install Verbex

Notes

  • Verbex now depends on the regex package (instead of Python's built-in re engine) for faster and more expressive pattern evaluation.
  • Quantifier methods default to possessive mode for performance (maybe, zero_or_more, one_or_more, n_times, n_times_or_more, n_to_m_times, anything).
  • If you need legacy backtracking behavior, pass possessive=False.
  • You can set the default quantifier behavior once per expression with Verbex(default_possessive=False).
  • OR(...) alternates only against the most recently added fragment. Use or_expr(...) to alternate against the full expression.

Usage

from verbex import Verbex
verbex = Verbex()

Documentation

API

Examples

Testing if we have a valid URL

from verbex import Verbex

# Create an example of how to test for correctly formed URLs
verbex = Verbex()
tester = (verbex.
            start_of_line().
            find('http').
            maybe('s').
            find('://').
            maybe('www.').
            anything_but(' ').
            end_of_line()
)

# Create an example URL
test_url = "https://www.google.com"

# Test if the URL is valid
if tester.regex().fullmatch(test_url):
    print("Valid URL")

# Print the generated regex
print(tester)  # Example: ^http?+://(?:www\.)?+[^ ]+$

Replacing strings

from verbex import Verbex

# Create a test string
replace_me = "Replace bird with a duck"

# Create an expression that looks for the word "bird"
expression = Verbex().find('bird')

# Compile and use the regular expression
regexp = expression.regex()
result_re = regexp.sub('duck', replace_me)
print(result_re)

Developer setup : running the tests

just tests

Other implementations

You can view all implementations on VerbalExpressions.github.io

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

verbex-3.0.0.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

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

verbex-3.0.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file verbex-3.0.0.tar.gz.

File metadata

  • Download URL: verbex-3.0.0.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for verbex-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c9a51dc5471142e972bf0f0ed8f6fb51ddab6e5c8b68375b6739ad4f112d7ba0
MD5 17d6e03fd6208ae9266be70c1fc609b4
BLAKE2b-256 3badaea282fdc707a27f9fd1f2a2251a5037cbc75da7e95b0e6cd4b53c9356d1

See more details on using hashes here.

File details

Details for the file verbex-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: verbex-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for verbex-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c447f928521273a8e95ca6b9e3e7bc14a29521bd21cdd03b2929282aec2b5058
MD5 9df5089084317f571148029c80b967f6
BLAKE2b-256 e2113d34d241c6c84a3d760031be96fca18682628210d23b11ee2793f2cb8403

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