import re
regex = re.compile(r"(^.*?((?:[A-Za-z]+_)+[A-Z]\w+)(?:-([0-9]{8}-[0-9]{6})-([0-9]{8}-[0-9]{6}))?)", flags=re.MULTILINE)
test_str = ("mixexecutor:check_atom_exists:740 - requested to check this machine : ET_colBackDDW_Temp \n\n"
"output_of_reports/PII/36478_ABP_BAL_liquidpressure-20210831-123456-20210831-172355.bat.yz\n\n"
"packofexecutors:_to_signle_que:869-no mata for file'/private/external_control_time_mapped_low_volume/IBA/54378_BD-RT_69-1-1-20200831-152355-20200831-172355.dat.xz'\n\n"
"packofexecutors:_to_signle_que:869-no mata for file'/private/external_control_time_mapped_low_volume/IBA/54378_BD-RT_69-1-20200831-152355-20200831-172355.dat.xz'\n\n"
"mixexecutor:check_atom_exists:740 - requested to check this machine : Eanes_colBack12_current\n\n"
"packofexecutors._check_tar.587-nr of missed files=78 nr of skipped records=6547 nr of records not exist=0\n\n"
"packofexecutors._filter_mistacl_signals:777 - invalid atomname for RT_6:ESmotormeaninfAmkl")
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