# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<=\D{3}.\d{2}.\d{4}).*(?<=\D)"
test_str = ("I N V O I C E **** JUL.19,2022\n"
"D A T E :\n"
"1-21, SHIBAURA 3-CHOME,MINATO-KU,TOKYO, JAPAN\n"
"NN390\n"
"INVOICE NO.\n"
"MITSUBISHI MOTORS AUSTRALIA LIMITED.\n"
"1 SIR RICHARD WILLIAMS AVENUE,\n"
"ADELAIDE AIRPORT SA 5950 AUSTRALIA\n"
"NAME OF VESSEL ON OR ABOUT LOADING PORT\n"
"OOCL NEW ZEALAND 115S JUL.30,2022 NAGOYA,JAPAN\n"
"DISCHARGING PORT INSURANCE\n"
"FREMANTLE,AUSTRALIA\n"
"COVERED BY SHIPPER\n"
"PAYMENT TERMS\n"
"REMITTANCE AT 45 DAYS AFTER B/L DATE\n"
"MARK & NOS DESCRIPTION QUANTITY UNIT PRICE AMOUNT\n"
"-AS PER SPARE PARTS FOR\n"
"ATTACHED SHEET- MITSUBISHI VEHICLES\n"
"PCS AUS.DOLLARS\n"
"*** ***********\n"
"FOB NET 2,553 75,622.32*\n"
"PACKING CHARGE 529.36*\n"
"FOB NAGOYA JAPAN 76,151.68*\n"
"INSURANCE 380.76*\n"
"C&I FREMANTLE 76,532.44*\n"
"**********\n"
"\"WE DECLARE THAT THE MACHINERY AND/OR PARTS AND\n"
"ACCESSORIES ARE NEW AND UNUSED AND HAVE NOT BEEN FIELD\n"
"TESTED OR FACTORY TRIALLED\"\n"
"PACKING LIST\n"
"LOT NO C/S NO GROSS WT NET WT M/M\n"
"MASAYUKI SHIBUYA GENERAL MANAGER\n"
"GLOBAL AFTER SALES LOGISTICS DEPARTMENT\n"
"GLOBAL AFTER SALES DIVISION\n"
"MITSUBISHI MOTORS CORPORATION\n"
"AV 0\n")
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