过滤Windows下保留的文件名称正则表达式

C++语法下实测:

^(?!(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9]|con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\\.[^.]*)?$)[^<>:\"/\\\\|?*\\x00-\\x1F]*[^<>:\"/\\\\|?*\\x00-\\x1F\\ .]$

bool editJsonFileNameandSolutionName::isValidFileName(const QString& fileName) {

    static QRegularExpression regex("^(?!(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9]|con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\\.[^.]*)?$)[^<>:\"/\\\\|?*\\x00-\\x1F]*[^<>:\"/\\\\|?*\\x00-\\x1F\\ .]$");

    return regex.match(fileName).hasMatch();
}

 

posted @ 2024-06-13 13:46  BlackSnow  阅读(24)  评论(0)    收藏  举报