main.cpp
#include <QCoreApplication>
#include <QRegExp>
#include <QString>
#include <QDebug>
#include <QStringList>
#include <QTextCodec>
void testRegexCapture();
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
testRegexCapture();
return a.exec();
}
void testRegexCapture()
{
QString plateNumber;
plateNumber = "1111京A75301aaaa";
// 截取车牌号码
plateNumber = plateNumber.simplified();
QRegExp rx("[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}");
int pos = rx.indexIn(plateNumber);
qDebug() << rx.capturedTexts();
}
输出结果: