Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java reg exp匹配模式与文件名_Java_Regex - Fatal编程技术网

Java reg exp匹配模式与文件名

Java reg exp匹配模式与文件名,java,regex,Java,Regex,我试图使用此模式检查来验证文件名Only.txt文本文件,但此模式不允许文件名包含句点,例如:a.b.有人建议我缺少什么吗?我认为最后第四行注释了零个或更多有效的文件名字符。应该没有圆点 我不确定从第二行到最后一行中的量词+是用来做什么的 另请参见您能否修复可能被格式化为代码的巨大块?有助于提高可读性。我刚刚编辑了它,很抱歉@BenKnobleNo的问题;我对regex一点也不了解,但有这种想法的人会很感激的。 Pattern.compile("# Match a valid Windows f

我试图使用此模式检查来验证文件名Only.txt文本文件,但此模式不允许文件名包含句点,例如:a.b.有人建议我缺少什么吗?

我认为最后第四行注释了零个或更多有效的文件名字符。应该没有圆点

我不确定从第二行到最后一行中的量词+是用来做什么的


另请参见

您能否修复可能被格式化为代码的巨大块?有助于提高可读性。我刚刚编辑了它,很抱歉@BenKnobleNo的问题;我对regex一点也不了解,但有这种想法的人会很感激的。
Pattern.compile("# Match a valid Windows filename (unspecified file system).    \n"
+ "^   # Anchor to start of string. \n"
+ "(?! # Assert filename is not: CON, PRN, \n"
+ "(?: # AUX, NUL, COM1, COM2, COM3, COM4, \n"
+ "CON|PRN|AUX|NUL| # COM5, COM6, COM7, COM8, COM9, \n"
+ "COM[1-9]|LPT[1-9]  # LPT1, LPT2, LPT3, LPT4, LPT5, \n"
+ " )  # LPT6, LPT7, LPT8, and LPT9... \n"
+ " +([.]txt) # followed by .txt    \n"
 "  $  # and end of string \n"
+ ")   # End negative lookahead assertion. \n"
+ "[^<>:\"/\\\\|?*\\x00-\\x1F.]*  # Zero or more valid filename chars.\n"
+ "[^<>:\"/\\\\|?*\\x00-\\x1F\\ .]  # Last char is not a space or dot.  \n"
+ "  +([.]txt)   # followed by .txt    \n"
+ "$   # Anchor to end of string.            ",
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE| Pattern.COMMENTS);
+ "[^<>:\"/\\\\|?*\\x00-\\x1F]*  # Zero or more valid filename chars.\n"