import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=\\n)[A-Za-z ]{4,44}\\s(\\d{3}|\\d{1}\\w{2})";
final String string = "ROBERTO S.R.L. \n"
+ "Automotive Aftermarket\n"
+ "Roberto S.R.L., Str. Horia Macelariu nr. 30-34, RO-013937 Bucuresti\n"
+ "Capitalul Social: 169.363.000 Lei, Nr. Ord. Reg. com.: J40/7601/1994 \n"
+ " \n"
+ "Citibank Europe Plc Dublin, Romania Branch Citibank Europe Plc Dublin, Bulgaria Branch \n"
+ "SWIFT CODE: CITIROBU SWIFT CODE: CITIBGSF \n"
+ "IBAN RON: RO45 CITI 0000 0007 2488 3001 IBAN BGN: BG54 CITI 9250 1001 0086 00 \n"
+ "IBAN EURO: RO48 CITI 0000 0007 2488 3044\n"
+ "Invoice 1/ 2\n"
+ "Document No.: 2045175575\n"
+ "Date: 09.01.2023\n"
+ "Sold To party: 22222222\n"
+ "Account No.: 22222222\n"
+ "ALFREDO GIOACCHINO OOD \n"
+ "ul. Andrey Germanov 11 \n"
+ "BG-1336 MILANO\n"
+ "Your VAT No.: BG175423111\n"
+ "Our VAT No.: RO5541546\n"
+ "Contact Person Finance: VALENTINA IVANOVA\n"
+ "Phone: +35929601062\n"
+ "E-mail: Valentina.Ivanova@bg.rocco.com\n"
+ "Contacts: DIANA DOBREVA\n"
+ "Phone: 878668802\n"
+ "E-mail: external.Diana.Dobreva@bg.rocco.com\n"
+ "Sold To Address: ALFREDO GIOACCHINO OOD, ul. Andrey Germanov 11, BG-1336 MILANO, B\n"
+ "Item Material/Description Quantity Unit Price per unit Net Value BGN\n"
+ "Transport: 1180774272 Shipping Point: ADC/LDC DE, Karlsruhe Shipping Type: Truck\n"
+ "Ship To Party: 95100938 ALFREDO GIOACCHINO OOD \n"
+ "ul. Andrey Germanov 11 \n"
+ "BG-1336 SOFIA\n"
+ "Delivery No.: 823025507 Delivery Date: 13.01.2023 Delivery Type: Standard Order AA\n"
+ "Your Order No.: 20230103-154257-011O From: 03.01.2023 Our Order No.: 210492510\n"
+ "10 Nozzle And Holder Assy 2 EA\n"
+ "Material: 0.432.231.664.80C\n"
+ "Material Entered: 0.432.231.664\n"
+ "EAN: 3165143215791\n"
+ "179,20 358,40\n"
+ "Dispatch element: 106650185 2 EA\n"
+ "20 Hole-Type Nozzle 4 EA\n"
+ "Material: 0.433.171.193.8GA\n"
+ "Material Entered: 0.433.171.193\n"
+ "EAN: 4047024542822\n"
+ "33,99 135,96\n"
+ "Dispatch element: 106650185 4 EA\n"
+ "Total net value: 494,36\n"
+ "VAT:* Z9 0,00 % 494,36 0,00\n"
+ "Invoice amount: 494,36\n"
+ "* Triangular transaction taxable at the customer according to Art. 141,2006/112/EC. This document is legally binding without signature.\n"
+ "Incoterms: DAP SOFIA\n"
+ "Payment terms: Up to 23.01.2023 you receive 2,000 % discount\n"
+ "Up to 08.02.2023 without deduction\n"
+ "Country of origin Index (represents the last three digits of part number)\n"
+ "Brazil 8GA\n"
+ "India 80CROBERTO S.R.L. \n"
+ "Automotive Aftermarket\n"
+ "Robert Bosch S.R.L., Str. Horia Macelariu nr. 30-34, RO-013937 Bucuresti\n"
+ "Capitalul Social: 169.363.000 Lei, Nr. Ord. Reg. com.: J40/7601/1994 \n"
+ " \n"
+ "Citibank Europe Plc Dublin, Romania Branch Citibank Europe Plc Dublin, Bulgaria Branch \n"
+ "SWIFT CODE: CITIROBU SWIFT CODE: CITIBGSF \n"
+ "IBAN RON: RO45 CITI 0000 0007 2488 3001 IBAN BGN: BG54 CITI 9250 1001 0086 00 \n"
+ "IBAN EURO: RO48 CITI 0000 0007 2488 3044\n"
+ "Invoice 2/ 2\n"
+ "Document No.: 2045175575\n"
+ "Date: 09.01.2023\n"
+ "Sold To party: 95100938\n"
+ "Account No.: 95100938\n"
+ "Country of origin HS Code Quantity UoM Amount BGN\n"
+ "Brazil\n"
+ "84099900 4 EA 135,96\n"
+ "135,96\n"
+ "India\n"
+ "84099900 2 EA 358,40\n"
+ "358,40\n"
+ "Marking Dispatch element type Physical dimension of dispatch \n"
+ "element\n"
+ "Unit of \n"
+ "measure\n"
+ "Gross \n"
+ "Weight Unit of measure\n"
+ "106650185 Corrugated carton 246 166 123 MM 0,959 KG\n"
+ "Country of origin Item numbers Total amount\n"
+ "Brazil 20 135,96\n"
+ "India 10 358,40\n"
+ "Element type: Corrugated carton Number of elements: 1 0,959 KG";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html