您的位置:首页 > 编程语言 > Python开发

Python 正则表达式验证URL

2014-10-09 10:37 351 查看
1. Allow almost any URL
^(https?|ftp|file)://.+$

eg. https://nihao.com/dddni.jpg 
2. Require a domain name, and donot allow a username or password
^(https?|ftp)://[a-zA-Z0-9-]+(\.[a-zA-Z0-9]+)+$

eg. https://nihao.com 
3. Require a domain name, and donot allow a username or password.
Allow the scheme (http or ftp) to be omitted if it can be inferred from the subdomain(www or ftp)
^((https?|ftp)://|(www|ftp)\.)[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+([/?].*)?$

eg. https://nihao.com/dddni.jpg www.nihao.com/dddni.jpg http://www.nihao.com/dddni.jpg 
4. Require a domain name and a path that points to an image file. Donot allow a username, password or parameters
^(https?|ftp)://[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+(/[\w-]+)*/[\w-]+\.(gif|png|jpg)$

eg. http://www.nihao.com/dddni.jpg[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: