int main(int argc, char *argv)
QCoreApplication a(argc, argv);
QString str="22.214.171.124 - - [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.]+)|[([^+)]|"([^"]+)"/");
qDebug() <<"String:"<< rx.cap(0);
qDebug() <<"IP Adrs:"<< rx.cap(1);
qDebug() << "Date & Time:"<<rx.cap(2);
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?
Check your regular expression
from Qt Assistant:
Note: The C++ compiler transforms backslashes in strings. To include a \ in a regexp, enter it twice, i.e. \. To match the backslash character itself, enter it four times, i.e. \\.
not [\d] but [\d]
Hi and welcome to devnet,
Please enclose your code in coding tags (one @ at the beginning and one at the end) to make it readable.
As AntonEml said, your reg exp is not valid. Check Qt's documentation for the subtleties. Also you can build the examples/tools/regexp example program to help you write the correct regexp
Also, use QRegularExpression instead of QRegExp. The latter is using a custom engine and is not fully compatible with Perl regexp syntax (so it may work different from your online checking tool). QRegularExpression, on the other hand, is based on PCRE and is basically a "has-it-all" package :)