import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[A-Z\\d]+\\s+\\d{4}-\\d{2}-\\d{2}\\s+\\w+(?:[ -]\\w+)*\\s+\\S+\\s+\\S+\\s+(\\S+)";
final String string = "2020-08-26 PILE OF LIFE HEALTH PRODUCTS LP Page 1 A/P Remittance Advice Direct Deposit 2020-08-26\n\n"
+ "Cheque # 11361 Vendor # 0828 HAIN CELESTIAL CANADA, ULC\n\n"
+ "Invoice # Date Description Gross Disc Net\n"
+ "===============================================================\n\n"
+ "225299 2020-07-24 P2156678 7,610.52 .00 7,610.52 \n"
+ "225839 2020-07-22 P2157105 7,826.28 .00 7,826.28 \n"
+ "225969 2020-07-22 P2157106 8,760.59 .00 8,760.59 \n"
+ "226384 2020-07-22 P2157104 42,274.76 .00 42,274.76\n"
+ "CR01BEPJ 2020-08-17 MULTI MCBS 4,470.06- .00 4,470.06-\n"
+ "CR01BEXS 2020-08-24 MULTI MCBS 5,212.81- .00 5,212.81-\n\n"
+ "DM20082311 2020-08-14 LIFESTYLE MARKETS NA 201.25- .00 201.25-\n"
+ "DM20083583 2020-08-17 KARDISH FOOD FRANCHI 281.37- .00 281.37-\n"
+ "DM20085965 2020-08-12 AVRILSUPERMARCHE-WAR 871.50- .00 871.50-\n"
+ "DM20086678 2020-08-12 AVRILSUPERMARCHE-WAR 871.50- .00 871.50-\n"
+ "DM20089459 2020-07-30 LOBLAWS 8.90- .00 8.90- \n"
+ "DM20089500 2020-08-14 COUNTRY GROCER-CHASE 105.00- .00 105.00-\n\n"
+ "========================================== 54,449.76 .00 54,449.76\n\n"
+ "Printed on 2020-08-26 at 6:26\n\n"
+ "2020-04-23 PILE OF LIFE HEALTH PRODUCTS LP Page 1 A/P Remittance Advice Direct Deposit 2020-04-23\n\n"
+ "Cheque # 9699 Vendor # 0828 HAIN CELESTIAL CANADA, ULC\n\n"
+ "Invoice # Date Description Gross Disc Net ===================================================================================\n\n"
+ "218124 2020-02-27 P2151168 2,253.44 .00 2,253.44 \n"
+ "219021 2020-03-18 P2152030 35,242.65 .00 35,242.65\n"
+ "219216 2020-03-18 P2152031 8,306.81 .00 8,306.81 \n"
+ "CR01BASW 2020-04-20 MULTI MCBS 5,278.05- .00 5,278.05-\n\n"
+ "DM2004W450 2020-04-17 RETURNS WFM-GR-20589 124.63- .00 124.63-\n"
+ "DM2004W828 2020-04-17 RETURNS WFM-GR-20589 266.09- .00 266.09-\n"
+ "DM20042157 2020-04-07 AVRIL 871.50- .00 871.50-\n"
+ "DM20043798 2020-04-07 COUNTRY GROCER 105.00- .00 105.00-\n"
+ "DM20043892 2020-04-07 COUNTRY GROCER 105.00- .00 105.00-\n"
+ "DM20048663 2020-04-07 AVRIL 871.50- .00 871.50-\n"
+ "DM20049986 2020-04-02 LA MOISSON 258.69- .00 258.69-\n\n"
+ "========================================== 37,922.44 .00 37,922.44\n\n"
+ "Printed on 2020-04-23 at 13:13";
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