[英]Regex for validate a website URL
The following regex: 以下正则表达式:
(http|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?
Is matched for the following: 符合以下条件:
https://something.com,
https://www.something.com,
http://something.com,
http://www.something.com
But the following is should not be match which is matched for the current regex: 但是以下内容不应该与当前正则表达式匹配:
https://www.something, http://www.something
And also the following is should be matched which is not matched for the current regex: 并且还应匹配以下与当前正则表达式不匹配的内容:
something.com, www.something.com
And also it matched for any domain, what I want to do is only accept known domains (such as: .com, .net, .biz etc). 而且它与任何域都匹配,我只想接受已知域(例如:.com,.net,.biz等)。
How can I improve the above regex? 如何改善上述正则表达式?
(:?(?:https?:\\/\\/)?(?:www\\.)?)?[-a-z0-9]+\\.(?:com|gov|org|net|edu|biz)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.