RegEx站点地址w /路径

时间:2013-02-12 08:00:43

标签: regex

请帮助为包含或不包含路径的网站制作正则表达式, 例如:

http://www.sitename.domain/dir/dir2/file.jpg
www.sitename.domain/dir/file.jpg
sub.sitename.domain/dir/dir2/file.jpg
site.do/file.pjg
https://go.do/dir/file.png
ftp://site.dom/file.blah_blah

确切的域名并不重要

1 个答案:

答案 0 :(得分:1)

如果要使用正则表达式匹配URL,可以使用:

^(((https?)|(ftp)):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$

您可以在http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/

上找到一些说明