Trouble with QRegularExpression
-
Hi all,
I need a little parser for some JSON strings.
Because my JSON string is quiet simple, I've tried to parse it with help ofQRegularExpression
.I first try to find Regex with help of Regex101.
But this regex does not work with Qt.
Can someone explain me what I am doing wrong?Hier the code extract:
QString jsonStr("{\"priority\":0,\"sat\":17,\"event\":239,\"rssi\":2,\"io200\":0,\"ignition\":false," "\"battery\":9.934000000000001,\"hdop\":0.6000000000000001,\"power\":25.739,\"io24\":0," "\"operator\":26201,\"io219\":4051331153808338998,\"io220\":3906362710332356403," "\"io221\":3977299914081173504,\"distance\":0.0,\"totalDistance\":-1.231416135E7,\"motion\":false}"); QRegularExpression jsonExtract("\"(\\w+)\":\"?([a-zA-Z0-9.\\-+]*)\"?"); auto jsonMatches = jsonExtract.globalMatch(jsonStr); if(jsonMatches.hasNext()) { auto m = jsonMatches.next(); qDebug() << m; }
EDIT
The output is:QRegularExpressionMatch(Valid, has match: 0:(1, 13, ""priority":0"), 1:(2, 10, "priority"), 2:(12, 13, "0"))
It must be obvious but I can see it :(
-
-
I did not check your regex but maybe first switch to raw string literals to make sure you don't have a
\
to much / missed somewhere? -
@Christian-Ehrlicher said in Trouble with QRegularExpression:
did not check your regex but maybe first switch to raw string literals to make sure you don't have a \ to much / missed somewhere?
I don't think so.
My problem is that I only got 1 match for the string.