fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7.  
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final String regex = "^([a-zA-Z0-9]+)\\s+Confirmed\\.on\\h+(\\d{1,2}/\\d{1,2}/\\d\\d)\\h+at\\h+(\\d{1,2}:\\d{1,2})\\w*Ksh(\\d+(?:\\.\\d+)?).*?\\bfrom\\h+(\\d+)\\h+([^.]+)\\.";
  13.  
  14. final String string2 = "PFEDDTYG0D Confirmed.on 14/6/21 at 12:46PMKsh260.00 received from 254725400049 JOHN DOE. New Account balance is Ksh1,666. Transaction cost, Ksh1";
  15. final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  16. final Matcher matcher = pattern.matcher(string2);
  17.  
  18. if(matcher.find()) {
  19. String code = matcher.group(1);
  20. String amountReceived = matcher.group(4);
  21. String tel = matcher.group(5);
  22. String from = matcher.group(6);
  23. String date = matcher.group(2);
  24. String time = matcher.group(3);
  25.  
  26. String format = "code: %s amount received: %s from: %s date: %s time: %s tel: %s";
  27. System.out.println(String.format(format, code, amountReceived, from, date, time, tel));
  28. }
  29. }
  30. }
Success #stdin #stdout 0.08s 48660KB
stdin
Standard input is empty
stdout
code: PFEDDTYG0D amount received: 260.00 from: JOHN DOE date: 14/6/21 time: 12:46 tel: 254725400049