pip install Verbex- Verbex now depends on the
regexpackage (instead of Python's built-inreengine) 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. Useor_expr(...)to alternate against the full expression.
from verbex import Verbex
verbex = Verbex()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\.)?+[^ ]+$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)just testsYou can view all implementations on VerbalExpressions.github.io