#include <QCoreApplication>
#include<QRegExp>
#include<QString>
#include<QDebug>
#include<QRegularExpression>
#include<QRegularExpressionMatch>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str="46.33.247.139 - - [05/Jan/2014:16:03:32 -0800] \\\\"GET /logs/access_130930.log HTTP/1.0\" 200 1251943 \"http://cytoteconline.jw.lt/200mcg\" \"Opera/9.80 (Windows NT 6.2; WOW64) Presto/2.12.388 Version/12.11\" \"redlug.com\"";
RegExp rx ("/([\d\.]+)|\[([^\[]+)\]|"([^"]+)"/");
rx.indexIn(str);
qDebug() <<"String:"<< rx.cap(0);
qDebug() <<"IP Adrs:"<< rx.cap(1);
qDebug() << "Date & Time:"<<rx.cap(2);
qDebug()<<"Aceess:"<<rx.cap(3);
qDebug()<<"Size:"<<rx.cap(4);
qDebug()<<rx.cap(5);
qDebug()<<rx.cap(6);
qDebug()<<rx.cap(7);
return a.exec();
}
Hi, i have to extract the fields from the string.Am using the regular expression for extraction.But it is not working correctly.Already test my regular expression in online regexp tester tool,at that time it match the string.My problem is that extraction is not working correctly.How it is possible? Any idea?
↧