简体   繁体   中英

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:

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

Found the answer,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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