QRegularExpression 是Qt 5.0才引进的,相对于QRegExp,QRegularExpression class修复了很多bug,提高了效率,提供了对Perl的RegEx几乎全面兼容的搜索引擎。简单说,QRegExp年久失修,bug较多,使用时建议使用QRegularExpression。
先上代码,后面逐函数简介:
QRegularExpression regularExpression(pattern);
int index = 0;
QRegularExpressionMatch match;
do {
match = regularExpression.match(testStr, index);
if(match.hasMatch()) {
index = match.capturedEnd();
qDebug()<<"("<<match.capturedStart() <<","<<index<<") "<<match.captured(0);
}
else
break;
} w