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