QString Pattern("[0-9]+");
QRegExp reg(Pattern);
QString str="465sf1";
//完全匹配,exactMatch("表达式")函数匹配相当于indexIn("^表达式$")。
if(reg.exactMatch(str))
{
qDebug()<<"匹配成功";
}
else {
qDebug()<<"匹配失败";
}
int pos = reg.indexIn(str,0);
while (pos!=-1) {
qDebug()<< reg.cap();
pos+=reg.matchedLength();
pos = reg.indexIn(str,pos);
}
输出结果:
匹配失败
"465"
"1"