python使用正则表达式检测给定的URL地址是否合法
#python使用正则表达式检测给定的URL地址是否合法
# python使用正则表达式检测给定的URL地址是否合法# Check if an URL is valid or not using Regular Expression# Python3 program to check# URL is valid or not# using regular expressionimport re# Function to validate URL# using regular expressiondef isValidURL(str):# Regex to check valid URLregex = ("((http|https)://)(www.)?" +"[a-zA-Z0-9@:%._\\+~#?&//=]" +"{2,256}\\.[a-z]" +"{2,6}\\b([-a-zA-Z0-9@:%" +"._\\+~#?&//=]*)")# Compile the ReGexp = pile(regex)# If the string is empty# return falseif (str == None):return False# Return if the string# matched the ReGexif(re.search(p, str)):return Trueelse:return False# Driver code# Test Case 1:url