I'm converting code from Javascript to Java and I found a regular expression that in Java doesn't work as expected (using the standard class Pattern).
It works fine in perl, js and also in Cocoa with NSRegularExpression
The reg exp is ([a-z]*) ([0-9]*)
and the java code is shown below
It must match two groups separated by a space, the first group contains only letters, the second group only numbers
public static void main(String[] args) {
Matcher matcher = Pattern.compile("([a-z]*) ([0-9]*)").matcher("hello 101");
while (matcher.find()) {
for (int i = 0; i < matcher.groupCount(); i++) {
System.out.println(i + ": " + matcher.group(i));
}
}
}
The numeric group is never returned. What is wrong?