首先,参考博客:
http://jamcode.iteye.com/blog/1397824
http://orzfly.com/html/regex-match-url.html
其次,总结出适合多样化的Url正则表达式:
e.g
var re=/^((http|https|ftp)://)?(w(:w)?@)?([0-9a-z_-]+.)*?([a-z]{2,6}(.[a-z]{2})?(:[0-9]{2,6})?)((/[^?#<>/\*":]*)+(?[^#]*)?(#.*)?)?$/i; assert(re.test("index.im")); assert(re.test("http://index.im")); assert(re.test("http://index.im/robots.txt")); assert(re.test("www.index.im/robots.txt")); assert(re.test("https://index.im/favicon.ico")); assert(re.test("http://www.index.im/?search=Go")); assert(re.test("websize/index.htm")); assert(re.test("http://www.index.im:80/home?search=Go")); //.............. //..............