Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 检查url是否为根url_Javascript_Regex - Fatal编程技术网

Javascript 检查url是否为根url

Javascript 检查url是否为根url,javascript,regex,Javascript,Regex,我正在寻找一个正则表达式来测试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

请尝试使用此正则表达式

(?\w+):/(?[\w@][\w.:@]+)/?[\w.?=%&=-@/$,]*

试试这个:

var str='url...';
if(str.indexOf("/")<str.indexOf(".")&&(str.indexOf("http://")>-1))
  return true;
else
  return fals;
var str='url…';
if(str.indexOf(“/”)-1))
返回true;
其他的
返回fals;

试试下面的
regex
就可以了

/^https?\:\/\/[^\/]+\/?$/
我是这样测试的:

var URL = "http://jsfiddle.net/";
var check =/^https?\:\/\/[^\/]+\/?$/.test(URL);
alert(check);

是否总是有一个“http://”?您是在测试当前URL,还是在测试
中的URL,还是在测试字符串中的URL?Gralien:是;Gareth:测试字符串,但是,添加查询字符串不起作用