import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\d+\\s+Timer.*?PHY Status 0x[01]+ - 0x[01].*?tx_p3a_d1en[\\s]+0[x\\w])+\\s+";
final String string = "000 Timer 0x00000000_0002a465 - 0x00000000_0021453e us: Gen1 - Gen1, DETECT.QUIET - DETECT.QUIET: Status 0x00000030 - 0x00000030: L2R_reason 0x00000000: PHY Status 0x01010000 - 0x01010000\n\n"
+ " Lane 00:\n\n"
+ " pga_gain 3, pga_off1 0, pga_off2 1, ph_ofs_t -44,\n\n"
+ " cdfe_a2 52, cdfe_a3 64, cdfe_a4 118, cdfe_a5 71, cdfe_a6 12, cdfe_a7 124, cdfe_a8 24, cdfe_a9 76, cdfe_a10 49,\n\n"
+ " zobel_a_gain 12, zobel_b_gain 0, zobel_dc_ofs 260, dc_ofs 25, udfe_thr_0 -152, udfe_thr_1 14, median_amp 179,\n\n"
+ " cdru_lock_count 0, eh_workaround_stat 0x0, los_toggle_cnt 0x8000, adapt_time 207872, cdr_lock_toggle_cnt 0x3000, jat_stat 0x804d\n\n"
+ " fs_obs 0, lf_obs 0, pre_cursor 0, cursor 0, post_cursor 0, usp_tx_preset 0x0, dsp_tx_preset 0x0\n\n"
+ " tx_p1a_d1en 0x30, tx_p1a_d2en 0xf, tx_p1a_amp_red 0x0, tx_p1b_d1en 0x3f, tx_p1b_d2en 0x0, tx_p1b_amp_red 0x0\n\n"
+ " tx_p2a_d1en 0x3f, tx_p2a_d2en 0x0, tx_p2a_amp_red 0x0, tx_p2b_d1en 0x3f, tx_p2b_d2en 0x0, tx_p2b_amp_red 0x0 tx_p3a_d1en 0x28\n\n"
+ " Lane 01:\n\n"
+ " pga_gain 15, pga_off1 24, pga_off2 6, ph_ofs_t -57,\n\n"
+ " cdfe_a2 -106, cdfe_a3 120, cdfe_a4 -80, cdfe_a5 -31, cdfe_a6 -13, cdfe_a7 127, cdfe_a8 96, cdfe_a9 127, cdfe_a10 4,\n\n"
+ " zobel_a_gain 0, zobel_b_gain 0, zobel_dc_ofs 457, dc_ofs 217, udfe_thr_0 -215, udfe_thr_1 219, median_amp 176,\n\n"
+ " cdru_lock_count 0, eh_workaround_stat 0x0, los_toggle_cnt 0x8000, adapt_time 207872, cdr_lock_toggle_cnt 0x3000, jat_stat 0x804d\n\n"
+ " fs_obs 0, lf_obs 0, pre_cursor 0, cursor 0, post_cursor 0, usp_tx_preset 0x0, dsp_tx_preset 0x0\n\n"
+ " tx_p1a_d1en 0x30, tx_p1a_d2en 0xf, tx_p1a_amp_red 0x0, tx_p1b_d1en 0x3f, tx_p1b_d2en 0x0, tx_p1b_amp_red 0x0\n\n"
+ " tx_p2a_d1en 0x3f, tx_p2a_d2en 0x0, tx_p2a_amp_red 0x0, tx_p2b_d1en 0x3f, tx_p2b_d2en 0x0, tx_p2b_amp_red 0x0 tx_p3a_d1en 0x28\n\n";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (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