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 fileName = "20210101-000000_first_second_1234.csv";
  9. Pattern pattern = Pattern.compile("\\d{4}(?=\\.[^.]+$)");
  10. Matcher m = pattern.matcher(fileName);
  11. if (m.find()) {
  12. System.out.println(m.group());
  13. }
  14. }
  15. }
Success #stdin #stdout 0.08s 40324KB
stdin
Standard input is empty
stdout
1234