How can I fetch a domain name from a URL String?
+----------------------+------------+ | input | output | +----------------------+------------+ | www.google.com | google | | www.mail.yahoo.com | mail.yahoo | | www.mail.yahoo.co.in | mail.yahoo | | www.abc.au.uk | abc | +----------------------+------------+
Related:
You can use nslookup on the IP. Reverse DNS is defined with the . in-addr.arpa domain. this will ask 3.2.21.123.in-addr.arpa and yield the domain name (if there is one defined for reverse DNS).
I once had to write such a regex for a company I worked for. The solution was this:
Example regex:
.*([^\.]+)(com|net|org|info|coop|int|co\.uk|org\.uk|ac\.uk|uk|__and so on__)$
This worked really well and also matched weird, unofficial top-levels like de.com and friends.
The upside:
The downside of this solution is of course:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With