import re
def validate_url(url):
pattern =
r'^(http|https)://([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,6})(/[a-zA-Z0-9.-]*)*([?][a-zA-Z0-9.-]*)*$'
if re.match(pattern, url):
return True
else:
return False
# Test the program
url_to_validate = input("Enter a URL: ")
if validate_url(url_to_validate):
print("Valid URL")
else:
print("Invalid URL")
No comments:
Post a Comment