我需要一个正则表达式,它将匹配下一个网址:
(http|https)://(www)<my domain here>
(http|https)://(www)<my domain here>/page1
(http|https)://(www)<my domain here>/page1/.../
(http|https)://(www)<my domain here>/page1/...?a=b
(http|https)://(www)<my domain here>/page1/...?a=b&c=d...
我有一个正则表达式,但我不知道如何编辑它
^(http:\/\/|https:\/\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?$
最佳答案
您可以使用以下内容:
^(http:\/\/|https:\/\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?(\/[a-z0-9])*(\/?|(\?[a-z0-9]=[a-z0-9](&[a-z0-9]=[a-z0-9]*)?))$
对于特定域名:
^(http:\/\/|https:\/\/)?(www.)?example\.com(\/?|(\?[a-z0-9]=[a-z0-9](&[a-z0-9]=[a-z0-9]*)?))$
编辑:验证域并获取网址:
(http:\/\/|https:\/\/)?(www.)?example\.com\S*
关于Java 的 URL 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32613720/