简体   繁体   English

Windows限制词的正则表达式

[英]Regular Expression for Windows Restricted Words

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

Because Windows filenames are not case sensitive you should don't forget the CASE_INSENSITIVE flag: 由于Windows文件名不区分大小写,因此您不应忘记CASE_INSENSITIVE标志:

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

For anyone who's interested - here is the MSDN link to the documentation of the Windows naming conventions: Naming Files, Paths, and Namespaces 对于任何感兴趣的人 - 这里是指向Windows命名约定文档的MSDN链接: 命名文件,路径和命名空间

Found the answer, 找到答案,

Pattern p= Pattern.compile("abc");
p.matcher("").matches();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM