How to code " in QT Regular Expression?
-
wrote on 9 May 2019, 13:58 last edited by VRonin 5 Sept 2019, 14:24
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;
-
wrote on 9 May 2019, 14:21 last edited by
@Subuday said in How to code " in QT Regular Expression?:
QRegularExpression bodyRegExp("\r\n\r\n(.*?)"");
IIRC, your RE must match THE WHOLE STRING to be valid ... IOW ".*\r\n\r\n(.*?)""
-
@Subuday said in How to code " in QT Regular Expression?:
QRegularExpression bodyRegExp("\r\n\r\n(.*?)"");
IIRC, your RE must match THE WHOLE STRING to be valid ... IOW ".*\r\n\r\n(.*?)""
wrote on 9 May 2019, 14:22 last edited by@Kent-Dorfman Sorry what do you mean?
-
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;
wrote on 9 May 2019, 14:25 last edited by@Subuday said in How to code " in QT Regular Expression?:
I have a text
Are you 100% sure the
"
are in the text and it's not just how it's displayed? -
@Subuday said in How to code " in QT Regular Expression?:
I have a text
Are you 100% sure the
"
are in the text and it's not just how it's displayed? -
wrote on 9 May 2019, 14:46 last edited by
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:
split -
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;
wrote on 9 May 2019, 15:10 last edited by Gojir4 5 Sept 2019, 15:33@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.
1/7