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
\/.+?\sIt 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(); } -
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
\/.+?\sIt 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(); } -
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"; -
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";@mranger90 Thank you!