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. How to code " in QT Regular Expression?
Forum Update on Monday, May 27th 2025

How to code " in QT Regular Expression?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 619 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.
  • S Offline
    S Offline
    Subuday
    wrote on 9 May 2019, 13:58 last edited by VRonin 5 Sept 2019, 14:24
    #1

    I have a text * "POST /test/123 HTTP/1.1\r\nHost: localhost:1234\r\nContent-Type: text/plain\r\nContent-Length: 24\r\nConnection: Keep-Alive\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,*\r\nUser-Agent: Mozilla/5.0\r\n\r\nMyBody" *

    I need to get MyBody text.

    I can't figure out how to code " because this doesn't work.

         QString test = "\\r\\n\\r\\MyBody\"";
    
        QRegularExpression bodyRegExp("\\r\\n\\r\\n(.*?)\"");
        QRegularExpressionMatch matchBody = bodyRegExp.match(test);
    
        qDebug() << matchBody;
    
    V G 2 Replies Last reply 9 May 2019, 14:25
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 9 May 2019, 14:21 last edited by
      #2

      @Subuday said in How to code " in QT Regular Expression?:

      QRegularExpression bodyRegExp("\r\n\r\n(.*?)"");

      IIRC, your RE must match THE WHOLE STRING to be valid ... IOW ".*\r\n\r\n(.*?)""

      S 1 Reply Last reply 9 May 2019, 14:22
      0
      • K Kent-Dorfman
        9 May 2019, 14:21

        @Subuday said in How to code " in QT Regular Expression?:

        QRegularExpression bodyRegExp("\r\n\r\n(.*?)"");

        IIRC, your RE must match THE WHOLE STRING to be valid ... IOW ".*\r\n\r\n(.*?)""

        S Offline
        S Offline
        Subuday
        wrote on 9 May 2019, 14:22 last edited by
        #3

        @Kent-Dorfman Sorry what do you mean?

        1 Reply Last reply
        0
        • S Subuday
          9 May 2019, 13:58

          I have a text * "POST /test/123 HTTP/1.1\r\nHost: localhost:1234\r\nContent-Type: text/plain\r\nContent-Length: 24\r\nConnection: Keep-Alive\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,*\r\nUser-Agent: Mozilla/5.0\r\n\r\nMyBody" *

          I need to get MyBody text.

          I can't figure out how to code " because this doesn't work.

               QString test = "\\r\\n\\r\\MyBody\"";
          
              QRegularExpression bodyRegExp("\\r\\n\\r\\n(.*?)\"");
              QRegularExpressionMatch matchBody = bodyRegExp.match(test);
          
              qDebug() << matchBody;
          
          V Offline
          V Offline
          VRonin
          wrote on 9 May 2019, 14:25 last edited by
          #4

          @Subuday said in How to code " in QT Regular Expression?:

          I have a text

          Are you 100% sure the " are in the text and it's not just how it's displayed?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          S 1 Reply Last reply 9 May 2019, 14:32
          3
          • V VRonin
            9 May 2019, 14:25

            @Subuday said in How to code " in QT Regular Expression?:

            I have a text

            Are you 100% sure the " are in the text and it's not just how it's displayed?

            S Offline
            S Offline
            Subuday
            wrote on 9 May 2019, 14:32 last edited by
            #5

            @VRonin QString
            Yes, I am sure and I try this example

            QString test = "\\r\\n\\r\\MyBody\"";
            
            1 Reply Last reply
            0
            • F Offline
              F Offline
              fcarney
              wrote on 9 May 2019, 14:46 last edited by
              #6
                  QString hworld("Hello World"); // there are no quotes in this string
                  qDebug() << hworld; // shows quotes
                  qDebug().noquote() << hworld; // shows no quotes
              

              You should consider dividing your string up to more bite sized chunks:
              split

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              0
              • S Subuday
                9 May 2019, 13:58

                I have a text * "POST /test/123 HTTP/1.1\r\nHost: localhost:1234\r\nContent-Type: text/plain\r\nContent-Length: 24\r\nConnection: Keep-Alive\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: en-US,*\r\nUser-Agent: Mozilla/5.0\r\n\r\nMyBody" *

                I need to get MyBody text.

                I can't figure out how to code " because this doesn't work.

                     QString test = "\\r\\n\\r\\MyBody\"";
                
                    QRegularExpression bodyRegExp("\\r\\n\\r\\n(.*?)\"");
                    QRegularExpressionMatch matchBody = bodyRegExp.match(test);
                
                    qDebug() << matchBody;
                
                G Offline
                G Offline
                Gojir4
                wrote on 9 May 2019, 15:10 last edited by Gojir4 5 Sept 2019, 15:33
                #7

                @Subuday I think your test string should be:

                QString test = "\r\n\r\\MyBody\"";
                

                You have to double escape backslash only in your regular expression.
                I suggest that you test your regular expression in a regex tester, like https://regex101.com, and then when it works, import it in your code. Otherwise it could be a nightmare to find the correct one.

                1 Reply Last reply
                5

                1/7

                9 May 2019, 13:58

                • Login

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