import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "all\\s+(\\S+\\s+){2}(?<field1>[\\d\\.]+)";
final String string = " 10/1/2017 0:10:01 all 9.13 0 1.68 6.6 0 82.59\n"
+ " 10/1/2017 0:20:01 all 7.46 0 0 5.74 0 85.17\n"
+ " 10/1/2017 0:30:01 all 9.05 0 129 1.53 0 88.13\n"
+ " 10/1/2017 0:40:01 all 7.77 0 1.45 1.23 0 89.54\n"
+ " 10/1/2017 0:50:01 all 7.08 0 1.5 1.41 0 90.02\n"
+ " 10/1/2017 1:00:01 all 6.46 0 1.43 1.82 0 90.29\n"
+ " 10/1/2017 1:10:01 all 45.4 0 4.2 29.27 0 21.13\n"
+ " 10/1/2017 1:20:01 all 61.74 0 4.74 31.19 0 2.32\n"
+ " 10/1/2017 1:30:01 all 64.17 0 4.72 26.31 0 4.81\n"
+ " 10/1/2017 1:40:01 all 47.54 0 4.23 19.44 0 28.79\n"
+ " 10/1/2017 1:50:01 all 44.59 0 3.68 17.47 0 34.27\n"
+ " 10/1/2017 2:00:01 all 49.16 0 4.22 13.47 0 33.15\n"
+ " 10/1/2017 2:10:01 all 41.98 0 3.95 16.47 0 37.59";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html