200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python使用正则表达式检测给定的URL地址是否合法

python使用正则表达式检测给定的URL地址是否合法

时间:2023-03-26 02:57:35

相关推荐

python使用正则表达式检测给定的URL地址是否合法

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。