import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?P<posting_date>\\d{2}/\\d{2}/\\d{4})\\s+(?P<transaction_date>\\d{2}/\\d{2}/\\d{4})\\s+(?P<description>[\\w\\s(),:]+?)\\s+(?P<Amount>-?\\d{1,3}(?:\\s\\d{3})*\\.\\d{2})\\s+(?P<Balance>-?\\d{1,3}(?:\\s\\d{3})*\\.\\d{2})$";
final String string = "26/01/2023 26/01/2023 Payment Received Z Kona 8 000.00 8 085.87\n"
+ "26/01/2023 26/01/2023 Banking App Payment: Sihle -2 000.00 6 085.87\n"
+ "26/01/2023 26/01/2023 Payment Fee -1.50 6 084.37\n"
+ "26/01/2023 26/01/2023 SMS Payment Notification Fee -0.25 6 084.12\n"
+ "26/01/2023 26/01/2023 Payment Received Z Kona 15 000.00 21 084.12\n"
+ "26/01/2023 26/01/2023 Payment Received Z Kona 1 500.00 22 584.12\n"
+ "26/01/2023 26/01/2023 Payment Received Z Kona 2 000.00 24 584.12\n"
+ "26/01/2023 26/01/2023 Banking App Transfer to Ms K Savings (1816578655) -18 500.00 6 084.12\n\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