import re
regex = re.compile(r"(?<=Tof MS\n).....................[0-9]+", flags=re.MULTILINE)
test_str = ("1. Q Legionella species kve/liter W57209\n"
"analysis conform, confirmation e.g. NEN-EN-ISO\n"
"11731 using MALDI-Tof MS\n"
"<100 < 100 < 100 < 100\n"
"ties 22\n"
"2. Monstervolume ml\n"
".Activitie\n"
"4. Assessment of AIDS, drinking water decision\n"
"norm 100 kve/litre\n"
"compliant compliant compliant\n"
"Order code\n"
"MonsterCode\n"
"Matrix\n"
"Customer code\n"
"Sample point description\n"
"Sampling date\n"
"Date of receipt")
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