我正在寻找一个正则表达式来测试一个 url 是否是一个根 url:
http://site.org TRUE
http://www.example.com TRUE
...
http://www.example.com/dir FALSE
http://www.example.com/image.jpg FALSE
http://www.example.com/dir/file.doc FALSE
我正在寻找一个正则表达式来测试一个 url 是否是一个根 url:
http://site.org TRUE
http://www.example.com TRUE
...
http://www.example.com/dir FALSE
http://www.example.com/image.jpg FALSE
http://www.example.com/dir/file.doc FALSE
试试下面regex
会做的工作
/^https?\:\/\/[^\/]+\/?$/
我是这样测试的:
var URL = "http://jsfiddle.net/";
var check =/^https?\:\/\/[^\/]+\/?$/.test(URL);
alert(check);
尝试这个:
var str='url...';
if(str.indexOf("/")<str.indexOf(".")&&(str.indexOf("http://")>-1))
return true;
else
return fals;
试试这个正则表达式
(?\w+)://(?[\w@][\w.:@]+)/?[\w.?=%&=-@/$,]*