import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainClass {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("(\\d{3,5})([a-z]{2})");
String string = "123aa-456bb-789cc-2fv";
Matcher matcher = pattern.matcher(string);
System.out.println(matcher.groupCount());
while (matcher.find()) {
System.out.println(matcher.group());
}
matcher.reset();
while (matcher.find()) {
System.out.println(matcher.group(1));
}
matcher.reset();
while (matcher.find()) {
System.out.println(matcher.group(2));
}
}
}
output:
2
123aa
456bb
789cc
123
456
789
aa
bb
cc