我正在尝试使用正则表达式验证给定的文件夹名称,我尝试了一些测试并且效果很好,如果我完全安全或者我的 reg 表达式遗漏了什么,请告诉我:
QRegExp regExp("^( [a-zA-Z] )( ( [a-zA-Z_\-\s0-9\.\)\(] )( [^\\!@#$%^&/:*?<>""|]* ) )*$" );
QStringList ForbidenNameU;
ForbidenNameU<<"CON"<<"PRN"<<"AUX"<<"NUL"<<"COM"<<"COM1"<<"COM2"<<"COM3"<<"COM4"<<"COM5"<<"COM6"<<"COM7"<<"COM8"<<"COM9"<<"LPT"<<"LPT1"<<"LPT2"<<"LPT3"<<"LPT4"<<"LPT5"<<"LPT6"<<"LPT7"<<"LPT8"<<"LPT9";
QStringList ForbidenName;
ForbidenName<<"con"<<"prn"<<"aux"<<"nul"<<"com"<<"com1"<<"com2"<<"com3"<<"com4"<<"com5"<<"com6"<<"com7"<<"com8"<<"com9"<<"lpt"<<"lpt1"<<"lpt2"<<"lpt3"<<"lpt4"<<"lpt5"<<"lpt6"<<"lpt7"<<"lpt8"<<"lpt9";
if((Dirname->text().contains(regExp))&& !ForbidenNameU.contains(Dirname->text())&& !ForbidenName.contains(Dirname->text()))
{
validname=true;
qDebug()<<"match in dir name = "<<regExp.cap(0);
emit completeChanged();
}...
PS(我不想使用GetInvalidFileNameChars()
或任何其他 api )
先感谢您。