Regexp to match domain and subdomains (in Java)

后端 未结 3 566
心在旅途
心在旅途 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:23

    you can use

    "http://a.domain.com".indexOf("domain.com") 
    

    this will return -1 if the requested string is not in the text.

    since you can don't want '.' after 'domain.com'

    you can can use

    "http://a.domain.com".indexOf("domain.com.")
    

    and check whether it is -1 or not

提交回复
热议问题