regexpython-3.xwhitelistdomain-name

Custom whitelisting domain names - Python3


In my project, I want to whitelist a set of domains to handle requests. It should allow all requests from the listed domain, its sub-domains and different pages on the domain.

So, if, for example, one of the whitelisted domains is example.com, it should serve requests for www.example.com, abc.example.com, https://abc.def.example.com, example.com/pg1 etc.

Which is the best utility/ library that can be used for this purpose? Or, do I need to write my own regex?


Solution

  • You can use the following regex to match subdomains of the domain example.com.

    ^([a-zA-Z0-9]+\.)*example\.com\/?.*