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
Forum Updated to NodeBB v4.3 + New Features

QRegularExpression

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 328 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.
  • M Offline
    M Offline
    Morgatte
    wrote on last edited by
    #1

    Hi,

    I would like to extract some QString

                /* My QString = "Lu 01/10/2023;2.60 m;4h16B;8h27M;16h46B;21h02M" */
                static const QRegularExpression re("\\d.\\d{1,2}");
                QRegularExpressionMatch match = re.match(ligne1);
                qDebug() << re.pattern();
    
                if (match.hasMatch()) {
                    a = match.captured(1);     // 2.60
                }
    
    
                qDebug() << "a =" << a;
    
                exit(0);
    

    even if I use re("\d.");
    or re("^\d$"); or anything else, nothing works.

    I do not anderstand.

    JonBJ 1 Reply Last reply
    0
    • M Morgatte

      Hi,

      I would like to extract some QString

                  /* My QString = "Lu 01/10/2023;2.60 m;4h16B;8h27M;16h46B;21h02M" */
                  static const QRegularExpression re("\\d.\\d{1,2}");
                  QRegularExpressionMatch match = re.match(ligne1);
                  qDebug() << re.pattern();
      
                  if (match.hasMatch()) {
                      a = match.captured(1);     // 2.60
                  }
      
      
                  qDebug() << "a =" << a;
      
                  exit(0);
      

      even if I use re("\d.");
      or re("^\d$"); or anything else, nothing works.

      I do not anderstand.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Morgatte
      What is it you want but don't get?? Your question is not clear. Do you get 2.60 or do you want 2.60 but not get it? I would assume it would match the 1/10 which comes early in the string? Or maybe 2023 if captured(1) is the second match. Actually you have no capturing groups, so I'm not sure captured(1) would ever return anything.

      Could you please actually qDebug() << ligne, and could you state whether it goes into the if (does it match? how many captures are in it?) and could you show the output from qDebug() << "a =" << a;. You can see the output, we cannot, we are not mind readers!

      In any case, since you intend your reg ex to capture a literal . between the digits I assume it should read

      "\\d\\.\\d{1,2}"
      
      1 Reply Last reply
      0
      • M Offline
        M Offline
        Morgatte
        wrote on last edited by
        #3

        thanks,

        I forgiven It.
        I used a simple

        .indexOf()
        .mid()

        That works.

        JonBJ 1 Reply Last reply
        0
        • M Morgatte

          thanks,

          I forgiven It.
          I used a simple

          .indexOf()
          .mid()

          That works.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @Morgatte Fine, well, QRegularExpression works OK so I don't know what you were expecting.

          1 Reply Last reply
          0

          • Login

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