import re
regex = re.compile(r"((?=\w+\d+_)\w+.fa)", flags=re.MULTILINE)
test_str = ("chr5 153584000 153599999 D16073_orphan_reads.fa;709[F18|R11] unkn 1 unkn 2509\n\n"
"chr7 153764000 153775999 D16073_orphan_reads.fa;710[F9|R21],14892_orphan_reads.fa;229[F19|R16] unkn 1 unkn 2510\n\n"
"chr3 127848000 127871999 B15971_orphan_reads.fa;172[F35|R6],D16157-14_orphan_reads.fa;183[F6|R13],14892_orphan_reads.fa;229[F19|R16],USP19283_orphan_reads.fa;336[F10|R6],D15927-14_orphan_reads.fa;176[F11|R10],1007,1007 46 1007 1658\n\n"
"(...)")
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