我想设置一个从行中查找时间的模式
String line = "INFO 00:08:39 - End executing test11093 : Next time will be Tue Nov 05 00:13:27 GMT 2013"
Pattern pTime = Pattern.compile("[0-9][0-9]:[0-9][0-9]:[0-9][0-9]");
Matcher mTime = pTime.matcher(line);
String dateTime = null;
while (mTime.find())
{
dateTime = mTime.group();
}
System.out.println(dateTime);
输出是:00:13:27,但是我只想第一次!
最佳答案
尝试添加中断;在dateTime = mTime.group()之后;或以这种方式更改代码
String dateTime = null;
if (mTime.find()) {
dateTime = mTime.group();
}