I am trying to match the sub domain and domain.
i used this code.
public static void main(String[] args) {
String s = "http://aaa.example.com";
Pattern pattern = Pattern.compile("http://([a-z0-9]*.)example.com");
Matcher matcher = pattern.matcher(s);
if (matcher.find()) {
System.out.println("match");
}
}
this works for http://aaa.example.com and also for http://aaa.example.commm. need to match only the sub domain for example.com
UPDATE :
Thanks for the answers and it works now i am facing another issue this regex is not matching http://example.com
Use matcher.matches() instead of find(). Matches will match the entire region against the pattern.