正则表达式仅在存在字符时才可以成功

 收藏

I am trying to construct a simple regex for detecting URLs. My progress is this regex: ^((https?):\/\/)?[\w.]*[\w]+\.[a-z]{3}\/?([\w\?\#.=-]+\/?)*$ But this is not actually what I want. This can detect URLs like:

https://something.com

www.stackoverflow.com

subdomain.domain.com/something/photo.png

但这也可以检测

subdomain.domain.communication

我的目标是:

There must be three characters in the domain ending (.com, .org, .net). There can be a / or not after the domain ending. But if only a / is present it should look into futher regex else it shold not match. Like it should detect:

https://somewebsite.com

https://somewebsite.com/

https://somewebsite.com/webpage/some#section

但不是:

https://something.commmm/

回复