Extract main domain name from a given url
问题 I used the following to extract the domain from a url: (They are test cases) String regex = "^(ww[a-zA-Z0-9-]{0,}\\.)"; ArrayList<String> cases = new ArrayList<String>(); cases.add("www.google.com"); cases.add("ww.socialrating.it"); cases.add("www-01.hopperspot.com"); cases.add("wwwsupernatural-brasil.blogspot.com"); cases.add("xtop10.net"); cases.add("zoyanailpolish.blogspot.com"); for (String t : cases) { String res = t.replaceAll(regex, ""); } I can get the following results: google.com