import re
regex = re.compile(r"Departure Date\/Time:(.{2,500}?\s)", flags=re.MULTILINE)
test_str = ("Document/Message Date/Time:2006-11-15T18:07 Booking Date/Time: 2006-11-15T19:00\n"
"Arrival Date/Time:2006-11-15T21:00 Departure Date/Time: 2006-11-15T21:30\n"
"Free Text\n"
"Goods Description: 1 PALLETS RECEIVED DAMAGED 1234561 PALLETS RECEIVED DAMAGED 123456\n"
"Non-acceptance Information:1 PALLETS RECEIVED DAMAGED 1234561 PALLETS RECEIVED DAMAGED 123456\n"
"Details of Transport\n"
"Haulier Number:ABCD5678901234567\n"
"Haulier’s Name:CARRIERS NAME456789 Wkjhutuytyut\n"
"Name and Address Message\n"
"Tesco Receiving Centre Number: AP3456789 Wduiyiu\n"
"Depot Number:CLP456789 WzkjdhusWE\n"
"Name & Address Description:DEPOT NAME Wdkwadyuw786X\n"
"Location Identification\n"
"Place/Port of Loading:AA3456789012345678901234xPlace of Transhipment:CC3456789012345678901234x\n"
"Place/Port of Discharge: BB3456789012345678901234x Bording Crossing Place:DD3456789012345678901234x")
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