Skip to content
This repository was archived by the owner on May 15, 2024. It is now read-only.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

26 Commits

Repository files navigation

PythonVerbalExpressions

Installation

pip install VerbalExpressions

Usage

fromverbalexpressionsimportVerExverbal_expression=VerEx()

Examples

Testing if we have a valid URL

# Create an example of how to test for correctly formed URLsverbal_expression=VerEx()
tester= (verbal_expression.
start_of_line().
find('http').
maybe('s').
find('://').
maybe('www.').
anything_but(' ').
end_of_line()
)
# Create an example URLtest_url="https://www.google.com"# Test if the URL is validiftester.match(test_url):
print"Valid URL"#Print the generated regexprinttester.source() # => ^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$

Replacing strings

#Create a test stringreplace_me="Replace bird with a duck"#Create an expression that looks for the word "bird"expression=VerEx().find('bird')
#Execute the expression in VerExresult_VerEx=expression.replace(replace_me, 'duck')
printresult_VerEx#Or we can compile and use the regular expression using reimportreregexp=expression.compile()
result_re=regexp.sub('duck', replace_me)
printresult_re

Shorthand for string replace

result=VerEx().find('red').replace('We have a red house', 'blue')
printresult

Developer setup : running the tests

python setup.py develop
python setup.py test

Other implementations

You can view all implementations on VerbalExpressions.github.io

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages