import re
regex = re.compile(r"\n1\s(\d{2,8})\s(\d{1,3}(?:\.\d{3})*(?:\,\d+))\s(\w{1,10})\s(\d{1,3}(?:\.\d{3})*(?:\,\d+))\s(\d{1,3}(?:\.\d{3})*(?:\,\d+))\s(\w{3})(?:\r?\n(?!Ihre).*)*\r?\nIhre Art.-Nr.\s(\d+)(?:\r?\n(?!DeliveryDate:|incl\.).*)*\r?\n(?:DeliveryDate:\s(\d{2}.\d{2}.\d{4}))?(?:\r?\n(?!incl\.).*)*\r?\nincl\.(?:ExtraCharge\r?\n\s*entspricht:\s(\d{1,3}(?:\.\d{3})*(?:\,\d+))\s(\w{1,10}))?", flags=re.MULTILINE)
test_str = ("\n"
"1 123456 25,00 Stck 100,00 2.500,00 EUR\n\n"
". . . some text\n\n"
"Ihre Art.-Nr. 1690431\n\n\n\n"
". . . some text\n\n"
"incl.\n\n\n\n"
"1 123456 25,00 Stck 100,00 2.500,00 EUR\n\n"
". . . some text\n\n"
"Ihre Art.-Nr. 1690431\n\n"
"DeliveryDate: 21.11.2019\n\n"
". . . some text\n\n"
"incl.ExtraCharge\n\n"
"entspricht: 222,00 EUR")
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