Q:

String url getting extension

I am trying to get the extension (dk, com, org, eu) or any other domain extension from a String.
for example:
http://www.example.com/siteone/sitetwo/currentpage

From this String i would like to get the .com 
I could go the very messy way around and do subString however the problem comes when an url looks like this:
dk.webpage.otherstuff.com/page

So how will i go around this in a way that doesnt require me to check everything every step of the way

A:

Use the getHost() method like this:
public static String getDomainName(String testUrl) throws URISyntaxException {
    URI fullUri = new URI(testUrl);
    String domainName = fullUri.getHost();
    return domainName.startsWith("www.") ? domainName.substring(4) : domainName;
}

After you have done that then just use subString for the .com part of your domain name.

