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})?)\\b.*$";
  16.  
  17. for (String s : strings) {
  18. System.out.println(s.replaceFirst(regex, "$1"));
  19. }
  20. }
  21. }
Success #stdin #stdout 0.08s 33224KB
stdin
Standard input is empty
stdout
70045620
70045620/2020