import re
regex = re.compile(r"(\d{8})\s*(\d{10})\s*([\d/]+)\s*([\d\.]+)\s*([\d\.]+)\s*([\d\.]+)", flags=re.MULTILINE)
test_str = ("\n"
" \n"
"We have effected a fund transfer to a/c No 00070110000017 with HDFC BANK for Rs\n"
"19,44,671.20(Rupees Ninteen Lakh Forty Four Thousand Six Hundred Seventy One and Paise\n"
"Twenty Only) against the below mentioned payment Details.\n"
"________________________________________________________________________________ \n"
"Invoice Number Document Number Document date Invoice Amount \n"
"Deductions Net Amount \n"
"________________________________________________________________________________ \n"
" 108027883 5001211394 28/12/2020 486167.80 \n"
" 0.00 486167.80 \n"
" 108027884 5001211396 28/12/2020 486167.80 \n"
" 0.00 486167.80 \n"
" 108027886 5001211401 28/12/2020 486167.80 \n"
" 0.00 486167.80 \n"
" 108027885 5001211408 28/12/2020 486167.80 \n"
" 0.00 486167.80 ")
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