Windows限制词的正则表达式

时间:2011-03-11 06:45:58

标签: java regex

如何编写正则表达式来捕获Windows限制名称,例如COM1或COM2或COM9(COM1或COM2或COM3 ....或COM9)。

2 个答案:

答案 0 :(得分:4)

由于Windows文件名不区分大小写,因此您不应忘记CASE_INSENSITIVE标志:

Pattern regex = Pattern.compile("CON|PRN|AUX|NUL|(COM|LPT)[1-9]", Pattern.CASE_INSENSITIVE);

对于任何感兴趣的人 - 这是指向Windows命名约定文档的MSDN链接:Naming Files, Paths, and Namespaces

答案 1 :(得分:0)

找到答案,

Pattern p= Pattern.compile("abc");
p.matcher("").matches();
相关问题