QRegularExpression Multiline stop matching first line

  • Hi guys, I'm writing a program that use Regular Expression and MultilineOption, I wrote this code but matching stop on first line. Why? What I'm doing wrong?

    QString recv = "AUTH-<username>-<password>\nINFO-ID:45\nREG-<username>-<password>-<name>-<status>\nSEND-ID:195-DATE:12:30 2/02/2015 <esempio>\nUPDATEN-<newname>\nUPDATES-<newstatus>\n";
    QRegularExpression exp = QRegularExpression("(SEND)-ID:(\\\d{1,4})-DATE:(\\\d{1,2}):(\\\d{2}) (\\\d{1,2})\\/(\\\d{2})\\/(\\\d{2,4}) <(.+)>\\\n|(AUTH)-<(.+)>-<(.+)>\\\n|(INFO)-ID:(\\\d{1,4})\\\n|(REG)-<(.+)>-<(.+)>-<(.+)>-<(.+)>\\\n|(UPDATEN)-<(.+)>\\\n|(UPDATES)-<(.+)>\\\n", QRegularExpression::MultilineOption);
        qDebug() << exp.pattern();
        QRegularExpressionMatch match = exp.match(recv);
        qDebug() << match.lastCapturedIndex();
        for (int i = 0; i <= match.lastCapturedIndex(); ++i) {
            qDebug() << match.captured(i);

    Can someone help me?

    Edited: Please put code after ```(3 backticks) and end with the same - p3c0

  • Hi and welcome do devnet,

    found some issues in your regexp

    • DATE:(\\\d{1,2}):(\\\d) should be DATE:(\\\d{1,2}):(\\\d{2})
    • (\\\d{1,2})\\/(\\\d)\\/(\\\d{2,4}) should be (\\\d{1,2})\\/(\\\d{1,2})\\/(\\\d{2,4})
    • in your regexp SEND-ID follows AUTH but in your string is not true

    BTW a simple solution to make debug easier could be to split the string in lines and process a line at time

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.