前言:
1、本文操作均为在vs2015+QT5.9.5版本中执行
2、本文操作是基于Qt窗口进行使用
main.cpp
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str = "xcxjxcxc123asdasdas 345 asdasd";
//正则表达式::查找位置
qDebug() << qUtf8Printable(QString::fromLocal8Bit("正则表达式::查找位置:")) << endl;
int pos = str.indexOf(QRegExp("[0-9]+"));
qDebug() << qUtf8Printable(QString::fromLocal8Bit("数字[0-9]+位置:"))<< pos<<endl;
//正则表达式::替换
qDebug() << qUtf8Printable(QString::fromLocal8Bit("正则表达式::替换:")) << endl;
QString str2 = str;
str2.replace(QRegExp("[0-9]+"), "[num]");
qDebug() << str2 << endl;
//正则表达式::切割
qDebug() << qUtf8Printable(QString::fromLocal8Bit("正则表达式::切割:")) << endl;
QStringList rlist = str.split(QRegExp("[0-9]+"));
for (int i = 0; i < rlist.size(); i++)
{
qDebug() << rlist[i] ;
}
return a.exec();
}