Update. Assume, that domain name are the last two items of the host name, except the second is co or com, in which case, domain name are the last three items. If there is just one item -> it is the domain name.
That the minimum cases to handle:
http://google.com -> google.com
http://www.google.com -> google.com
http://abc.cde.google.com -> google.com
http://google.co.uk -> google.co.uk
http://www.google.com.au -> google.com.au
http://www.mysite.info -> mysite.info
http://www.mysite.business -> mysite.business
http://localhost -> localhost
Regex sandbox for this question
Here are the tests and some starting regexp https://regex101.com/r/AyuW88/3
As a bonus, a few more cases (but I would be already very happy if regex works just with the former cases)
http://google.com:8080 -> google.com
http://www.google.com?q=abc -> google.com
http://www.google.com/smth -> google.com