import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "SID_W_MAX_TRAN_DT.+?=(?=\\s) (?<SID_W_MAX_TRAN_DT>[^\\s]+)";
final String string = "MID_COUNT =========== 20,588,655\n"
+ " % Total % Received % Xferd Average Speed Time Time Time Current\n"
+ " Dload Upload Total Spent Left Speed\n"
+ "Table.+.+?(?=\\.)\\W*(schema.table_name)\\W.+?(?=,+)\\,\\s+numRows\\=+(?<LogTime>[^\\,]+)\n\n"
+ "Loading data to table schema.table_name\n"
+ "Table gmr.opcode_tedc_cs_gmr_id_delta stats: [numFiles=5, numRows=8986691, totalSize=937732401, rawDataSize=928745710]\n\n"
+ " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n"
+ "100 997 100 997 0 0 114k 0 --:--:-- --:--:-- --:--:-- 162k\n\n"
+ " 0 0 0 397 0 0 1650 0 --:--:-- --:--:-- --:--:-- 1650\n"
+ "SID_W_MAX_TRAN_DT ========== 9,070,691\n"
+ " % Total % Received % Xferd Average Speed Time Time Time Current\n"
+ " Dload Upload Total Spent Left Speed\n\n"
+ " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n"
+ "100 997 100 997 0 0 108k 0 --:--:-- --:--:-- --:--:-- 139k\n\n"
+ " 0 0 0 403 0 0 944 0 --:--:-- --:--:-- --:--:-- 944\n"
+ "NON_PSP_SID_COUNT =========== 39,869,169\n"
+ " % Total % Received % Xferd Average Speed Time Time Time Current\n"
+ " Dload Upload Total Spent Left Speed\n\n"
+ " 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n"
+ "100 997 100 997 0 0 112k 0 --:--:-- --:--:-- --:--:-- 162k\n\n"
+ " 0 0 0 398 0 0 7223 0 --:--:-- --:--:-- --:--:-- 7223\n"
+ "PSP_SID_COUNT =========== 45,083\n";
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