fork(9) download
  1. import java.util.Date;
  2. import java.util.regex.Pattern;
  3. import java.util.regex.Matcher;
  4. import java.text.SimpleDateFormat;
  5.  
  6. public class Main {
  7. public static void main(String[] args) throws Exception {
  8. String filename = "19882012ABCseptemberDEF03HIJ12KLM0156_249.zip";
  9. String regex = "(.*?)([0-9]{4})([^0-9]*?)([a-z]+)(.*?)([0-9]{2})(.*?)([0-9]{2})(.*?)([0-9]{4})_([^.]+)[.]zip";
  10. Matcher m = Pattern.compile(regex).matcher(filename);
  11. if (m.matches()) {
  12. System.out.println("it does match");
  13. String dateString =m.group(2) + "-" + m.group(4) + "-" + m.group(6) + " " + m.group(8) + m.group(10);
  14. System.out.println("extracted: " + dateString);
  15. Date date = new SimpleDateFormat("yyyy-MMM-dd HHmmss").parse(dateString);
  16. // here you go with your date
  17. System.out.println(date);
  18. } else {
  19. System.out.println("it does not match");
  20. }
  21. }
  22.  
  23. }
Success #stdin #stdout 0.11s 216384KB
stdin
Standard input is empty
stdout
it does match
extracted: 2012-september-03 120156
Mon Sep 03 12:01:56 GMT 2012