import re
regex = re.compile(r"^((qwarebatch[0-9]?_((g?p(tres|[fse])|lc|ra|darf?|n[edlcs]|ob|gru_intra))_)|([AG]F|[EL]?[CO]([ACDV])?|D[CIL]|NT))[0-9]{5,8}\.TXT.*", flags=re.IGNORECASE | re.MULTILINE)
test_str = ("qwarebatch_nc_20140714.TXT\n"
"AF32503.txt\n"
"CV4130214.TXT\n"
"CA5070515.TXT\n"
"CD4130115.txt\n"
"CC4130214.TXT\n"
"DI41102.txt\n"
"qwarebatch_dar_20150602.TXT\n"
"qwarebatch_darf_20150602.TXT\n"
"DC4130214.TXT\n"
"DL4160214.TXT\n"
"EC5070515.TXT\n"
"GF41102.txt\n"
"GP41102.TXT\n"
"qwarebatch_gru_intra_20150602.TXT\n"
"qwarebatch_lc_20150602.TXT\n"
"LO4130214.TXT\n"
"NT32503.txt\n"
"qwarebatch_nd_20150602.TXT\n"
"qwarebatch_ne_20150602.TXT\n"
"qwarebatch_nl_20150602.TXT\n"
"qwarebatch_ns_20150602.TXT\n"
"qwarebatch_ob_20150602.TXT\n"
"qwarebatch_pe_20140618.TXT\n"
"qwarebatch_pf_20150602.TXT\n"
"qwarebatch2_ptres_20150602.TXT\n"
"qwarebatch_ra_20150602.TXT")
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