搂着这个要看情况更具文件名特点来,
如果都是AD开头,那么:AD_.*?\.pdf
如果文件名没有特点,但是在路径中:[\\/].*?\.pdf
总之要弄懂原理灵活运用
import java.util.regex.*;
// 表达式对象
Pattern p = Pattern.compile("(jpg|gif)");
// 创建 Matcher 对象
Matcher m = p.matcher("abc.gif");
// 是否完全匹配
boolean yesorno = m.matches();
String reg = "(?i)^\\w+\\.(pdf|jpeg)$";
我次奥楼上几位,为什么不用endsWith?! 匹配pdf或者JPEG文件名,不用正则表达式这么复杂啊!