fork(25) download
  1. import java.util.regex.*;
  2.  
  3. class Main
  4. {
  5. public static void main (String[] args) throws java.lang.Exception
  6. {
  7. Pattern p = Pattern.compile("/[^/]+\\.(.*)");
  8. String[] tests = { "/var/www.dir/file.tar.gz", "/var/www.dir/file.exe" };
  9. for (String s : tests) {
  10. String lastPart = s.substring(s.lastIndexOf("/"));
  11. String file = s.substring(s.lastIndexOf("/"));
  12. String extension = file.substring(file.indexOf(".")); // .tar.gz
  13. System.out.println(extension);
  14. }
  15. }
  16. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
.tar.gz
.exe