我将如何解析以下字符串中的两个数字:
String fName = "Run_1_vs_2_pw_optimal_mapping.txt";
我试过这样,但它不起作用:
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;
}
但是,这不起作用,因为scanner.group(0) 返回Run_1_vs_2
。但为什么?