QRegularExpression, implying regex on data contains NULL character
-
Hello,
I am trying to parse some inputs that can have multiple NULL characters in it but I couldnt make it word, here is code I tried.QByteArray data = "[12]Hello\0\0World"; QRegularExpression reg("(?<h1>\\[.*\\])(?<h2>.*)"); reg.setPatternOptions(QRegularExpression::DotMatchesEverythingOption); QRegularExpressionMatchIterator itr = reg.globalMatch(data); while(itr.hasNext()) { QRegularExpressionMatch match = itr.next(); qDebug() << match.captured("h2"); }
I want it to print HelloWorld but all I can see is Hello,
Thank you. -
It does not even compile. Since a QString should not contain a \0 (and you don't show how you convert your
data
tostr
) I doubt this will work at all with a regexp. Looks like another problem which shows a use of a regex where a simple search and replace would be much more efficent and understandable. -
Hello,
I am trying to parse some inputs that can have multiple NULL characters in it but I couldnt make it word, here is code I tried.QByteArray data = "[12]Hello\0\0World"; QRegularExpression reg("(?<h1>\\[.*\\])(?<h2>.*)"); reg.setPatternOptions(QRegularExpression::DotMatchesEverythingOption); QRegularExpressionMatchIterator itr = reg.globalMatch(data); while(itr.hasNext()) { QRegularExpressionMatch match = itr.next(); qDebug() << match.captured("h2"); }
I want it to print HelloWorld but all I can see is Hello,
Thank you.@ikuris said in QRegularExpression, implying regex on data contains NULL character:
QRegularExpression reg("(?<h1>\\[.*\\])(?<h2>.*)");
Separately from the correct observations of my colleagues. What are
\\[
and\\]
doing here inside a C literal? What are you trying to achieve with these?