I hate Excel - Extracting a domain name from a hostname

Assuming that cell B2 has a hostname like foo.bar.baz.example.com the following will extract just the domain name form the hostname, e.g. "example.com"

=CONCATENATE(RIGHT(LEFT(B2,LEN(B2)-4),LEN(LEFT(B2,LEN(B2)-4))-FIND("|",SUBSTITUTE(LEFT(B2,LEN(B2)-4),".","|",LEN(LEFT(B2,LEN(B2)-4))-LEN(SUBSTITUTE(LEFT(B2,LEN(B2)-4),".",""))))),RIGHT(B2,4))

Of course this doesn't work if you really care about supporting all the TLDs in the world but seriously, why was that so hard Excel?

The same thing (with the same TLD issue), in Python (hat tip to StackOverflow):

url = 'http://foo.bar.baz.example.com' '.'.join(urlparse.urlparse(url).netloc.split('.')[-2:])

Go read the entire StackOverflow post to understand how to deal with TLDs but in case you're not always so lucky to have Python and have to use Excel, there you go. If anyone has any better ways to extract the domain in excel, please let me know.