Solved Problem with using RegExp
-
I need to determine /hello.htm in string GET /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 \r\n using RegExp. I use
\/.+?\s
It wokrs fine on Online Regular Expression
but in qt it doesn'tQRegExp uriRegExp("\/.+?\s"); int lastPos = 0; while((lastPos = uriRegExp.indexIn(myString, lastPos)) != -1) { qDebug() << uriRegExp.cap(1); lastPos += uriRegExp.matchedLength(); }
-
-
@jsulm Doesn't work
-
qDebug() << "Starting"; QString testString("GET /hello.htm HTTP/1.1 User-Agent: Mozilla/4.0 \r\n "); QRegularExpression re("/.+?\\s"); QRegularExpressionMatch match = re.match(testString); if (match.hasMatch()) { QString matched = match.captured(0); qDebug() << "Matched " << matched; } else { qDebug() << "No match"; } qDebug() << "done";
-
@Subuday Should be
QRegExp uriRegExp("\\/.+?\\s");
\ is escape character in C++, if you want to use it as part of a string you have to escape it as \\
-
@mranger90 Thank you!