import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\(groupid=\\s+(?P<groupid>\\d+)";
final String string = "seq_read_4k: (groupid= 0 jobs= 1): err= 0: pid= 7396: Wed Sep 2 14:07:25 2015\n"
+ " read : io= 72013 MB bw= 614510 KB/s iops= 153627 runt= 120001msec \n"
+ "-- \n"
+ "seq_read_128k: (groupid= 1 jobs= 1): err= 0: pid= 7463: Wed Sep 2 14:07:25 2015\n"
+ " read : io= 74277 MB bw= 633821 KB/s iops= 4951 runt= 120001msec \n"
+ "-- \n"
+ "rand_read_4k: (groupid= 2 jobs= 1): err= 0: pid= 7480: Wed Sep 2 14:07:25 2015\n"
+ " read : io= 4102.4 MB bw= 35006 KB/s iops= 8751 runt= 120001msec \n"
+ "-- \n"
+ "rand_read_1M: (groupid= 3 jobs= 1): err= 0: pid= 7497: Wed Sep 2 14:07:25 2015\n"
+ " read : io= 44963 MB bw= 383678 KB/s iops= 374 runt= 120002msec \n";
final Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE);
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