How would I parse the two numbers in the following string:
String fName = "Run_1_vs_2_pw_optimal_mapping.txt";
I tried it like this, but it doesn’t work:
Pattern filePatt = Pattern.compile("Run_(\\d+)_vs_(\\d+)_", Pattern.CASE_INSENSITIVE);
Matcher scanner = this.filePatt.matcher(fName);
while (scanner.find()) {
int groupSize = scanner.groupCount();
if (groupSize == 2) {
firstRun = Integer.parseInt(scanner.group(0));
secondRun = Integer.parseInt(scanner.group(1));
}
break;
}
However, this doesn’t work, because scanner.group(0) returns Run_1_vs_2. But why?
See the documentation.
Use
group(1)andgroup(2).