我的下载文件夹中有一些带有特定字符串模式的 pdf 文件。我需要获取最新保存的文件。
我的代码是
public static void main(String args[])
    {
        String directory=System.getProperty("user.home")+"\\Downloads";
        File dir=new File(directory);
        for(File file:dir.listFiles())
        {
            if(file.getName().endsWith(".pdf"))
            {
                String res=file.getName();
                match(res);
                //System.out.println(file.getName());
            }
        }
    }
    private static void match(String res) {
String pattern="[a-zA-Z][0-9][0-9]CR[0-9][0-9][0-9][0-9]-[a-zA-Z][a-zA-Z][a-zA-Z]-[A-Z]-[0-9] \\(\\d+\\).pdf";
        Pattern r=Pattern.compile(pattern);
        Matcher m=r.matcher(res);
        if(m.find())
        {
            System.out.println("******* Match *********"+m.group());
        }
        else
        {
            System.out.println("******No match*******");
        }
}
我的输出是这样的
******* Match *********F90CR0010-HBR-C-4 (5).pdf
******* Match *********F90CR0010-HBR-C-4 (6).pdf
******* Match *********F90CR0010-HBR-C-4 (7).pdf
现在我需要找到大括号()内编号最大的文件。所以在这种情况下我需要
******* Match *********F90CR0010-HBR-C-4 (7).pdf
这里如何匹配正则表达式中的最大整数?
谢谢