我试图从这个表单中获取数字
使用这个表达式
该数字不应具有字母+空格+整数+整数+空格的形式。
我该如何解决?
28
,该表单包含整数+空格+整数+整数+空格+整数。我尝试使用这个正则表达式\\s\\d\\d\\s
,但是它会得到两个数字11
和28
。使用这个表达式
\\d\\s\\d\\d\\s\\d
时,我遇到了这个错误java.lang.NumberFormatException: For input string: "4 60 1"
。该数字不应具有字母+空格+整数+整数+空格的形式。
我该如何解决?
ZOB/Hauptbahnhof Bussteig 11 20:04 20:34 28 21:08 21:40 22:08 22:40 23:08 23:40 00:30
代码:
Pattern pattern = Pattern.compile("\\s\\d\\d\\s");
//Pattern pattern = Pattern.compile("\\d\\s\\d\\d\\s\\d");
Matcher m = pattern.matcher(line);
while (m.find()) {
value = Integer.parseInt(m.group().trim());
if (value != 10) {
line = line.replace(m.group(), " ").replaceAll(" +", " ");
writer.println("Min:" + value);
// String line3 = scanner.nextLine();
System.out.println(value
+ " has been found in this text document " + newName);
}
}