正常表达式下面没有www
/((?:https?\:\/\/|www\.)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)/i
我检查过以下网址
http://regexr.com (working, match)
http://www.regexr.com/ (working, match)
www.regexr.com (working, match)
regexr.com (not working, should be match)
abc@gmail.com (working, not match)
如果我使用下面的代码
((?:https?\:\/\/|)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)
然后它也匹配电子邮件ID
abc@gmail.com (not working, should not match)
答案 0 :(得分:1)
答案 1 :(得分:0)
正则表达式正常,更多信息click here
^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$
工作,因为它匹配以下Url'而不是电子邮件ID
www.regexr.com
regexr.com
abc@gmail.com(工作,与电子邮件ID不匹配)