我试图检查特殊字符。我试过了:
QString test;
test = "Hello";
QRegExp re("[^A-Za-z0-9]");
if (!re.exactMatch(test))
{
log("False");
}
返回False
另外
int icount = test.count(QRegExp("[!@#$%^&()_+]"));
返回> 0
我不知道自己做错了什么!
我需要知道QString是否包含除有效之外的任何其他字符:A-Z,a-z,0-9
答案 0 :(得分:0)
尝试QRegExp::indexIn()
QRegExp re("[^A-Za-z0-9]");
if (re.indexIn("Hello") < 0)
qDebug() << "No special chars";
else
qDebug() << "Found at least one special char";
if (re.indexIn("Hello.") < 0)
qDebug() << "No special chars";
else
qDebug() << "Found at least one special char";
输出:
No special chars
Found at least one special char