Regexp to match domain and subdomains (in Java)

后端 未结 3 565
心在旅途
心在旅途 2021-01-15 15:00

I need to verify if given URL matches my domain mask.

Example: I want to allow only domains which satisfy this \"pseudo-mask\":

https://*.domain.com
         


        
3条回答
  •  鱼传尺愫
    2021-01-15 15:21

    ^https?://[^/@]*\.domain\.com(/.*)?$
    

    (The not-/ to stop .domain.com appearing in the path, the not-@ to stop username:password@ abuse.)

    Better, though: use the URL class built into Java to parse a URL properly. You can then just read the host property and check that it endsWith your domain.

提交回复
热议问题