# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\|\|[0-9]+\s*[0-9]+\s*\|\|([0-9]{6}-[0-9]{4}-[0-9]{3}\S*)\|\|.*?Bestellnr\.K\/Pos\s*?([0-9]+)\s*?([0-9]+)\|\|.*?Charge:\s*?(\S+)\s*?Gesamtmenge:\s*?([0-9\.]+)\s*?ST"
test_str = "||10 980008530||000000-2209-165-EXE||Unverl. Kombischr._M5x25_UE_Nitronic_ISR||Nitronic60||3fach verpackt||10er Setverpackung||Reinigung und Verpackung nach VACOM Purity Class 4 / ZEISS 1000711||Bestellnr.K/Pos 1926779 1||Ihre Materialnr.: 000000000002209165-EXE||Charge: 0009114369 Gesamtmenge: 999 ST||Handling Unit: 10030337466 999 ST||20 980008530||000000-1234-999-EXE||Unverl. Kombischr._M5x25_UE_Nitronic_ISR||Nitronic60||3fach verpackt||10er Setverpackung||Reinigung und Verpackung nach VACOM Purity Class 4 / ZEISS 1000711||Bestellnr.K/Pos 1926779 1||Ihre Materialnr.: 000000000002209165-EXE||Charge: 0009114369 Gesamtmenge: 123456 ST||Handling Unit: 10030337466 999 ST||30 980008530||000000-8888-165-EXE||Unverl. Kombischr._M5x25_UE_Nitronic_ISR||Nitronic60||3fach verpackt||10er Setverpackung||Reinigung und Verpackung nach VACOM Purity Class 4 / ZEISS 1000711||Bestellnr.K/Pos 1926779 1||Ihre Materialnr.: 000000000002209165-EXE||Charge: 0009114369 Gesamtmenge: 999 ST||Charge: 000777777 Gesamtmenge: 22222 ST||Handling Unit: 10030337466 999 ST"
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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