# 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