import re
regex = re.compile(r"(?:(?<=^)|(?<=\n{2}))PASS.+?(?!FAIL).+?CLPM_FPGA_(\d{2})", flags=re.IGNORECASE | re.DOTALL)
test_str = ("PASS: PLL Lock signal state at reset is 0.\n"
"PASS: PLL Lock signal state is 1.\n"
"PASS: PLL Locked within expected time: 5000000 ps.\n"
"Requirements verified: CLPM_FPGA_31\n\n"
"PASS: System Clock high period is 8000 ps.\n"
"FAIL: System Clock low period is 8000 ps.\n"
"PASS: System Clock period is 16000 ps.\n"
"Requirements verified: CLPM_FPGA_32\n\n"
"PASS: System Clock to IFC delay is 10 ps.\n"
"Requirements verified: CLPM_FPGA_33\n\n"
"PASS: System Clock to IFC delay is 10 ps.\n"
"Requirements verified: CLPM_FPGA_34\n\n"
"FAIL: System Clock low period is 8000 ps.\n"
"PASS: System Clock high period is 8000 ps.\n"
"PASS: System Clock period is 16000 ps.\n"
"Requirements verified: CLPM_FPGA_35\n\n"
"PASS: System Clock high period is 8000 ps.\n"
"PASS: System Clock period is 16000 ps.\n"
"FAIL: System Clock low period is 8000 ps.\n"
"Requirements verified: CLPM_FPGA_36\n\n"
"FAIL: System Clock low period is 8000 ps.\n"
"Requirements verified: CLPM_FPGA_37\n\n"
"PASS: System Clock to IFC delay is 10 ps.\n"
"FAIL: System Clock low period is 8000 ps.\n"
"Requirements verified: CLPM_FPGA_39\n\n"
"PASS: System Clock to IFC delay is 10 ps.\n"
"Requirements verified: CLPM_FPGA_40")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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 Python, please visit: https://docs.python.org/3/library/re.html