Makes difficult regular expressions easier to handle
verbalexpressions.py
# -*- coding: utf-8 -*-
from verbalexpressions import VerEx
verbal_expression = VerEx()
tester = (verbal_expression.
start_of_line().
find('http').
maybe('s').
find('://').
maybe('www.').
anything_but(' ').
end_of_line()
)
test_url = "https://www.google.com"
if tester.match(test_url):
print "Valid URL"
# Valid URL
print tester.source()
# ^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$
Recommended Posts