# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<=KilometreSI I\\r\\n\*).[0-9\s]+"
test_str = "El\\r\\n_I ERNST&YOUNC Expense Report\\r\\nI Date Prepared: 01-08-2019 I Managing Country: XE I\\r\\nI Submitted: 01-08-2019 (In Audit) | Business Unit: XE045 I\\r\\n| GPN - Name: XE021000618 — Paul Prashanth | Management Unit: 00801 Sub Management Unit: 0907302 |\\r\\nI Signature: I Approved By: Rank: I\\r\\nI Rank: Administrative Contractor I Approval Signature: I\\r\\nI Expense Details (Attach supporting receipts) I Total Net IC = Chargeable P = Authorized I\\r\\nI Loc I Expense Type I Date I Description I Expense Expense I Type I Engagement I Activity I\\r\\nOTHER International Travel-Non-Billable - Ground 01-08-2019 Need clarification for claiming the taxi expenses P 33800872 0000\\r\\nTransportation - Mass/Public Transportation from same vendor for INR 2400 & No receipts fo\\r\\nTelephone for GBP l (INR 97.89) & Taxi for GB\\r\\n25 (INR 2470.75) Barcode : 2170270878\\r\\nI IIIIII IIIII IIIII IIIII IIIII IIIII IIIII IIIII IIIII IIIII IIII IIII Tom’s I 0.00 I 0.00 I Tom] KilometreSI I\\r\\n* 2 1 7 1 9 5 9 5 2 8 it Report Date Format: dd-mm-yyyy\\r\\nPage 1 of 1 10-06-2020"
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