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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM