如下是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)