Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QRegularExpression Multiline stop matching first line
QtWS25 Last Chance

QRegularExpression Multiline stop matching first line

Scheduled Pinned Locked Moved General and Desktop
qregularexpressregex multiline
2 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PeterBlack
    wrote on 27 Mar 2015, 14:35 last edited by p3c0
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on 28 Mar 2015, 12:12 last edited by mcosta
      #2

      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

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0

      1/2

      27 Mar 2015, 14:35

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved