import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?i)PRZED ODLICZ\\.[\\s\\a]*ZAL\\.\\/ZAD\\.[\\s\\a]*-[\\s\\a]*Zestawienie[\\s\\a]*podatku[\\s\\a]*VAT[\\s\\a]*Netto[\\s\\a]*Stawka[\\s\\a]*VAT[\\s\\a]*Brutto[\\s\\a]*(?<PrzedOdl>(?<PrzedOdlWartoscNetto>\\d[\\d ]*,\\d{2})[\\s\\a]*(?<PrzedOdlStawkaVAT>\\d+%)[\\s\\a]*(?<PrzedOdlKwotaVAT>\\d[\\d ]*,\\d{2})[\\s\\a]*(?<PrzedOdlWartoscBrutto>\\d[\\d ]*,\\d{2}))[\\s\\a]*ODLICZENIE[\\s\\a]*ZAL\\.\\/ZAD\\.[\\s\\a]*-[\\s\\a]*Zestawienie podatku[\\s\\a]*VAT[\\s\\a]*Netto[\\s\\a]*Stawka[\\s\\a]*VAT[\\s\\a]*Brutto[\\s\\a]*(?<Odl>(?<OdlWartoscNetto>[-]?\\d[\\d ]*,\\d{2})[\\s\\a]*(?<OdlStawkaVAT>\\d+%)[\\s\\a]*(?<OdlKwotaVAT>[-]?\\d[\\d ]*,\\d{2})[\\s\\a]*(?<OdlWartoscBrutto>[-]?\\d[\\d ]*,\\d{2}))[\\s\\a]*Zestawienie[\\s\\a]*podatku[\\s\\a]*VAT[\\s\\a]*Netto[\\s\\a]*Stawka[\\s\\a]*VAT[\\s\\a]*Brutto[\\s\\a]*RAZEM[\\s\\a]*\\((?<IloscProduktow>\\d+)[\\s\\a]*Poz\\.?\\)[\\s\\a]*(?<WartoscNetto>\\d[\\d ]*,\\d{2})([\\s\\a]*(?<StawkaVAT>\\d+%)|)[\\s\\a]*(?<KwotaVAT>\\d[\\d ]*,\\d{2})[\\s\\a]*(?<WartoscBrutto>\\d[\\d ]*,\\d{2})[\\s\\a]*SUMA[\\s\\a]*OGÓŁEM[\\s\\a]*\\k<WartoscBrutto>";
final String string = "ODATNIK:\n"
+ "Rogum Kable Sp. z o.o. 83-000 Pruszcz Gdański\n"
+ "ORYGINAŁ\n"
+ "Pruszcz Gdański, 2020-04-28\n"
+ "\n"
+ "Grunwaldzka 66\n"
+ "\n"
+ "Bank: Bank Polska Kasa Opieki SA\n"
+ "\n"
+ "NIP : 957-00-17-373\n"
+ "\n"
+ "Konto: 57124012681111001033938599\n"
+ "\n"
+ "/\n"
+ "FAKTURA VAT 207/04/2020\n"
+ "Data wystawienia : 2020-04-28 Data sprzedaży : 2020-04-28\n"
+ " \n"
+ "Na podstawie : T530992 , z dnia: 2019-12-28\n"
+ " \n"
+ "NABYWCA : Pojazdy Szynowe PESA Bydgoszcz S.A.\n"
+ "(811) : Zygmunta Augusta 11 Bydgoszcz, 85-082 \n"
+ "NIP : 554-031-17-75\n"
+ "Operator prowadzący : Łukasz Czajkowski, Tel.: 506234233, E-mail: l.czajkowski@rogum.com.pl\n"
+ "/\n"
+ "Poprzednie zaliczki/zadatki: Fzal 54/04/2020 2020-04-06 (246 000,00)\n"
+ "Lp\n"
+ "Nazwa pełna\n"
+ "Ilość\n"
+ "Jm\n"
+ "Cena\n"
+ "Wartość\n"
+ "Stawka\n"
+ "Wartość\n"
+ "Wartość\n"
+ "Indeks (K)\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "NETTO PL\n"
+ "NETTO PLN\n"
+ "VAT\n"
+ "VAT PLN\n"
+ "BRUTTO PLN\n"
+ "\n"
+ "\n"
+ "1\n"
+ "LiHCH 0,6/1kV 3x1,5\n"
+ "200\n"
+ "m\n"
+ "2,70\n"
+ "540,00\n"
+ "23%\n"
+ "124,20\n"
+ "664,20\n"
+ "9124-1100-000-075\n"
+ "\n"
+ "2\n"
+ "LiHCH 0,6/1kV 3x1,5\n"
+ "86\n"
+ "m\n"
+ "2,70\n"
+ "232,20\n"
+ "23%\n"
+ "53,41\n"
+ "285,61\n"
+ "9124-1100-000-075\n"
+ "\n"
+ "PRZED ODLICZ. ZAL./ZAD. - Zestawienie podatku VAT\n"
+ "Netto\n"
+ "Stawka\n"
+ "VAT\n"
+ "Brutto\n"
+ "\n"
+ " \n"
+ "772,20\n"
+ "23%\n"
+ "177,61\n"
+ "949,81\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "ODLICZENIE ZAL./ZAD. - Zestawienie podatku VAT\n"
+ "Netto\n"
+ "Stawka\n"
+ "VAT\n"
+ "Brutto\n"
+ "\n"
+ " \n"
+ "-772,20\n"
+ "23%\n"
+ "-177,61\n"
+ "-949,81\n"
+ "\n"
+ " \n"
+ "Zestawienie podatku VAT\n"
+ "Netto\n"
+ "\n"
+ "Stawka\n"
+ "VAT\n"
+ "\n"
+ "Brutto\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "RAZEM (2 Poz.)\n"
+ "\n"
+ "0,00\n"
+ " \n"
+ "\n"
+ "0,00\n"
+ "0,00\n"
+ "\n"
+ "SUMA OGÓŁEM\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "0,00\n"
+ "\n"
+ "\n"
+ " \n"
+ "Słownie : zero złotych, zero groszy\n"
+ " \n"
+ "DO ZAPŁATY : 0,00 zł Rozliczono\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ "Sara Żołnowska\n"
+ " \n"
+ " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n"
+ "podpis osoby upoważnionej pieczęć i podpis wystawiającego do odbioru Faktury VAT\n"
+ "Druk Streamsoft PRESTIŻ lic. 5529 v. 7.0.347.168 Str. 1 z 1\n";
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