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
Python 正则表达式验证URL
最新推荐文章于 2023-04-05 16:31:03 发布