T
Timo Nentwig
Hi!
I need to convert an domain name into an array:
www.inter.net -> { "www", "inter", "net" }
I want to use a regex but don't get it how to pre-determine the number of
groups (i.e. dots+1). Sample program:
public static void main(String[] args)
{
String ip = "a.bc.def.g.h";
Pattern pat = Pattern.compile("(\\w)+");
Matcher mat = pat.matcher(ip);
System.out.println(mat.groupCount()); // == 1
while (mat.find())
{
System.out.println(mat.group());
}
}
Isn't it possible to pre-determine the group count?
Regards
Timo
I need to convert an domain name into an array:
www.inter.net -> { "www", "inter", "net" }
I want to use a regex but don't get it how to pre-determine the number of
groups (i.e. dots+1). Sample program:
public static void main(String[] args)
{
String ip = "a.bc.def.g.h";
Pattern pat = Pattern.compile("(\\w)+");
Matcher mat = pat.matcher(ip);
System.out.println(mat.groupCount()); // == 1
while (mat.find())
{
System.out.println(mat.group());
}
}
Isn't it possible to pre-determine the group count?
Regards
Timo