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. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String[] strings = {
  12. "71346 G249 USD 70045620 27/08/2020 001 / 004",
  13. "71346 G249 USD 70045620/2020 27/08/2020 001 / 004"
  14. };
  15. String regex = "\\b[0-9]{6,}(?:/[0-9]{4})?";
  16.  
  17. Pattern pattern = Pattern.compile(regex);
  18.  
  19.  
  20. for (String s : strings) {
  21. Matcher matcher = pattern.matcher(s);
  22. if (matcher.find()) {
  23. System.out.println(matcher.group(0));
  24. }
  25. }
  26. }
  27. }
Success #stdin #stdout 0.09s 33652KB
stdin
Standard input is empty
stdout
70045620
70045620/2020