Reputation: 1896
Is there a way in JVM (preferably in Java or a small library) to have the following regex (?<Hour>\\d\\d)*
and to be able to extract all the hours? For example if "12131415" is given then to be able to get a collections of hours something like {12,13,14,15}.
Does groovy support this?
Upvotes: 1
Views: 54
Reputation: 174826
The below regex would capture each two digits and stores it into separate groups.
Your code would be,
String s = "12131415";
Pattern p = Pattern.compile("(?<Hour>\\d{2})");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group(1));
}
Upvotes: 1