#include <QCoreApplication>
#include <QRegExp>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QRegExp re(".."); //表达式
QString str = "aaa;;;;a,,,,,,a";
if(re.exactMatch(str)) //验证
{
qDebug()<<"true";
}
else
{
qDebug()<<"false";
}
int pos=0;
/*截取匹配OK的字段*/
while ((pos = re.indexIn(str,pos)) != -1) {
qDebug()<<re.cap();
pos += re.matchedLength();
}
return a.exec();
}
源码链接QT 5.9.1+MSVC2015:https://pan.baidu.com/s/1hugXV1a
关于正则表达式的表达式就先不贴了。