fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String regex = "^(\\w+)\\s.*?(\\d{1,2}/\\d{1,2}/\\d{2,})\\s+at\\s+(\\d{1,2}:\\d{1,2}).*?Ksh([\\d,.]+)\\s.*?from\\s+(\\d+)\\s+([a-zA-Z\\s]+)";
  9. String string = "QAP04N99TG Confirmed.on 25/1/22 at 1:57 PMKsh1.00 received from 1123123322 JOHN DUE MARTIN. New Account balance is Ksh10.00. Transaction cost, Ksh0.00.";
  10. Pattern pattern = Pattern.compile(regex);
  11. Matcher matcher = pattern.matcher(string);
  12. while(matcher.find()) {
  13. String txnCode = matcher.group(1);
  14. String date = matcher.group(2);
  15. String time = matcher.group(3);
  16. String amount = matcher.group(4);
  17. String account = matcher.group(5);
  18. String username = matcher.group(6);
  19. System.out.println(txnCode+">"+date+">"+time+">"+amount+">"+account+">"+username);
  20. }
  21. }
  22. }
Success #stdin #stdout 0.2s 54932KB
stdin
Standard input is empty
stdout
QAP04N99TG>25/1/22>1:57>1.00>1123123322>JOHN DUE MARTIN