我写了这个正则表达式([0-9]{2}:){2}[0-9]{2},[0-9]{3} -> ([0-9]{2}:){2}[0-9]{2},[0-9]{3}来匹配 srt 时间格式00:16:31,600 -> 00:16:35,700,当我像这样使用它时它工作正常:someString.matches(timeSpanPattern)但是当我hasNext(pattern)在下面的代码中使用它时,它总是返回 false,我认为这是因为之前和之后的空格->。有什么替代方法或代码可以防止这种情况发生吗?我尝试useDelimiter了函数,但它没有用(可能我错误地使用了这个函数)
final String timeSpanPattern = "([0-9]{2}:){2}[0-9]{2},[0-9]{3} -> ([0-9]{2}:){2}[0-9]{2},[0-9]{3}";
.
.
.
Scanner i = new Scanner(System.in).useDelimiter("\n");
while (i.hasNext(timeSpanPattern)) {
line = i.next(timeSpanPattern);
forbiddenTimes.add(line);
}
.
.
.