Reputation: 11
I want to set a pattern which will find a time from line
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);
The output is : 00:13:27, but I want to get only the first time!
Upvotes: 1
Views: 59
Reputation: 135992
Try to add break; after dateTime = mTime.group(); or change the code this way
String dateTime = null;
if (mTime.find()) {
dateTime = mTime.group();
}
Upvotes: 2