文件名模式不起作用,涉及YYYYMMDD

时间:2013-08-13 10:36:15

标签: java regex

Regex pattern: hnm_sarai_ntpl_((19|20)\\d\\d)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])
File name: hnm_sarai_ntpl_20130808

我从远程位置获取文件为FTPFile。 我希望将其名称与提到的正则表达式相匹配。

List<String> fileNamePatterns=new ArrayList<String>();
fileNamePatterns.add("hnm_sarai_ntpl_((19|20)\\d\\d)(0?[1-9]|1[012])(0?[1-9]|[12][0-9]|3[01])");

FTPFile file; //file's name is = hnm_sarai_ntpl_20130808

Pattern p = Pattern.compile(_fileNamePatterns.get(0));
Matcher m = p.matcher(file.getName());
if (m.matches()) {
    return file.getName();
} else {
    return "";
}

该代码段始终返回"",我希望文件名与给定的正则表达式匹配。 知道为什么它不匹配吗?

0 个答案:

没有答案