1、正则表达式这么写String s = "img.png";String regex = ".*\\.png";System.out.println(s.matches(regex));//true 2、可以直接用endsWith()函数if(s.endsWith(".png")) { }