How to code " in QT Regular Expression?
I have a text
* "POST /test/123 HTTP/1.1\r\nHost: localhost:1234\r\nContent-Type: text/plain\r\nContent-Length: 24\r\nConnection: Keep-Alive\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,*\r\nUser-Agent: Mozilla/5.0\r\n\r\nMyBody" *
I need to get MyBody text.
I can't figure out how to code " because this doesn't work.
QString test = "\\r\\n\\r\\MyBody\""; QRegularExpression bodyRegExp("\\r\\n\\r\\n(.*?)\""); QRegularExpressionMatch matchBody = bodyRegExp.match(test); qDebug() << matchBody;
IIRC, your RE must match THE WHOLE STRING to be valid ... IOW ".*\r\n\r\n(.*?)""
@Kent-Dorfman Sorry what do you mean?
I have a text
Are you 100% sure the
"are in the text and it's not just how it's displayed?
Yes, I am sure and I try this example
QString test = "\\r\\n\\r\\MyBody\"";
QString hworld("Hello World"); // there are no quotes in this string qDebug() << hworld; // shows quotes qDebug().noquote() << hworld; // shows no quotes
You should consider dividing your string up to more bite sized chunks:
@Subuday I think your test string should be:
QString test = "\r\n\r\\MyBody\"";
You have to double escape backslash only in your regular expression.
I suggest that you test your regular expression in a regex tester, like https://regex101.com, and then when it works, import it in your code. Otherwise it could be a nightmare to find the correct one.