Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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 验证google文档和office 365 url_Javascript_Regex - Fatal编程技术网

Javascript 验证google文档和office 365 url

Javascript 验证google文档和office 365 url,javascript,regex,Javascript,Regex,我使用正则表达式验证提供的url是否有效。为了测试有效性(谷歌文档url或office 365文档),我做了以下操作,但不起作用 var url = "https://hello-my.sharepoint.com/:w:/r/personal/; var urlRegx = new RegExp('^(docs.google.com|(http|https)://[A-Za-z]-.my.sharepoint.com)', 'i'); console.log(urlRegx.test(url)

我使用正则表达式验证提供的url是否有效。为了测试有效性(谷歌文档url或office 365文档),我做了以下操作,但不起作用

var url = "https://hello-my.sharepoint.com/:w:/r/personal/;
var urlRegx = new RegExp('^(docs.google.com|(http|https)://[A-Za-z]-.my.sharepoint.com)', 'i');
console.log(urlRegx.test(url));

当我有sharepoint url时,这给了我
false
,但当我有`url=“docs.google.com/document/”

时,你在表达式末尾有一个额外的结束括号
,你应该删除它

[a-Za-z]
之后,您还缺少一个
+
(因为没有加号,您只匹配一个字符)

以下是一个工作示例:

var url=”https://hello-my.sharepoint.com/:w:/r/personal/";
var urlRegx=new RegExp('(docs.google.com |(http | https))(://[A-Za-z]+-my.sharepoint.com)?','i');

log(urlRegx.test(url))尝试
var urlRegx=/^(?:docs\.google\.com | https?:\/\/[A-Za-z]+-my\.sharepoint\.com/i。看,你还是没逃过一劫。请参阅
console.log('\.')
。在使用RegExp构造函数构建的正则表达式模式中,不需要转义
/
/
不是特殊的正则表达式元字符。@WiktorStribiżew-Ah是的,你说得对。谢谢你指出这一点。我已经更新了我的答案,如果你试图验证“docs.google.com”的url,它会将false作为output@milan尝试
newregexp('(docs.google.com |(http | https))(://[A-Za-z]+-my.sharepoint.com)?,'i')取而代之