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

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

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