从提取出来这个图片的URL
#include <QtCore/QCoreApplication>
#include <QRegExp>
#include <qdebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QRegExp rx(QString("<a href=\"(.*)\""));
QString str("<a href=\"/qq575787460/article/details/7866370\">");
int pos=str.indexOf(rx);
qDebug()<<pos;
if(pos>=0)
{
qDebug()<<rx.matchedLength();
qDebug()<<rx.cap(0);
qDebug()<<rx.cap(1);
qDebug()<<rx.pos(0);
qDebug()<<rx.pos(1);
}
return a.exec();
}
QRegExp中匹配到的整个表达式:rx.cap(0)
正则表达式中的括号,从左到右依次为1,2,3,4。。。。
匹配的值依次存于rx.cap(1),rx.cap(2),rx.cap(3),rx.cap(4).....