QString str = "3639BACB 3639BACC";
QRegularExpression re("[0-9]{4}[A-E]{4}");
int index = 0;
while(index < str.length())
{
auto match = re.match(str, index);
if(match.hasMatch())
{
index = match.capturedEnd();
QString sub = match.captured(0);
qDebug()<<sub;
}
else
break;
}
qDebug()<<"-------------------";
QRegExp exp("[0-9]{4}[A-E]{4}");
int pos = 0;
while ((pos = exp.indexIn(str, pos)) != -1)
{
pos += exp.matchedLength();
auto str1 = exp.cap(0);
qDebug()<<str1;
}
二者效果相同