Python验证Url地址的正则表达式,python正则表达式,Python验证Url地


Python验证Url地址的正则表达式

如下是django中做url验证的正则表达式:

regex = re.compile(        r'^(?:http|ftp)s?://' # http:// or https://        r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...        r'localhost|' #localhost...        r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip        r'(?::\d+)?' # optional port        r'(?:/?|[/?]\S+)$', re.IGNORECASE)

评论关闭