Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Re: Regular exp
QtWS25 Last Chance

Re: Regular exp

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 4 Posters 1.7k 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.
  • N Offline
    N Offline
    Naveen_D
    wrote on 17 Aug 2017, 07:15 last edited by
    #1

    Hi all,

    I am using Qprocess to start another process which gives me the following output from the started process.

    \n\n+HTTPACTION:0,200,15\n\nAT+HTTPREAD\n\n\n\n+HTTPREAD:15\n\nHead_Light_On \n\n\nOK\n\n \r\n\n"

    I want only Head_Light_On from the above output, i am using regular exp to match the output and send that particular output to one of my qml file. but i am not getting how to get that particular output using reg exp.
    Can anyone help me in this matter.

    Thank you.

    Naveen_D

    M 1 Reply Last reply 17 Aug 2017, 09:35
    0
    • N Naveen_D
      17 Aug 2017, 07:15

      Hi all,

      I am using Qprocess to start another process which gives me the following output from the started process.

      \n\n+HTTPACTION:0,200,15\n\nAT+HTTPREAD\n\n\n\n+HTTPREAD:15\n\nHead_Light_On \n\n\nOK\n\n \r\n\n"

      I want only Head_Light_On from the above output, i am using regular exp to match the output and send that particular output to one of my qml file. but i am not getting how to get that particular output using reg exp.
      Can anyone help me in this matter.

      Thank you.

      M Offline
      M Offline
      m.sue
      wrote on 17 Aug 2017, 09:35 last edited by m.sue
      #2

      Hi @Naveen_D

      The answer highly depends on how mutable the rest of the string is. E.g. if the rest is always the same or of the same length just search at the position.

      -Michael.

      N 1 Reply Last reply 17 Aug 2017, 10:03
      0
      • M m.sue
        17 Aug 2017, 09:35

        Hi @Naveen_D

        The answer highly depends on how mutable the rest of the string is. E.g. if the rest is always the same or of the same length just search at the position.

        -Michael.

        N Offline
        N Offline
        Naveen_D
        wrote on 17 Aug 2017, 10:03 last edited by Naveen_D
        #3

        @m.sue No, the rest of the string is not same it depends on the server, what command i am receiving, i want a generic reg exp for this.
        this is the code i am trying

        const QRegularExpression regXp("HTTPREAD:15\n\n\\s*(.+)");
            const auto regXpMatch = regXp.match(processOut);
            if(regXpMatch.hasMatch()){
                qDebug() << "Output of regular exp is: "<< regXpMatch.captured(1);
            }
        

        but in the above the number "15" is not same, every time it changes when the data from the sever changes.

        Naveen_D

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 17 Aug 2017, 10:37 last edited by
          #4

          Hi,

          \d+ means one or more number. Don't forget to double the \ in your string.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          N 1 Reply Last reply 17 Aug 2017, 10:43
          0
          • S SGaist
            17 Aug 2017, 10:37

            Hi,

            \d+ means one or more number. Don't forget to double the \ in your string.

            N Offline
            N Offline
            Naveen_D
            wrote on 17 Aug 2017, 10:43 last edited by
            #5

            @SGaist

            Don't forget to double the \ in your string.

            Sorry i didn't get in which string.

            Naveen_D

            M 1 Reply Last reply 17 Aug 2017, 11:18
            0
            • K Offline
              K Offline
              Kaluss
              wrote on 17 Aug 2017, 10:56 last edited by Kaluss
              #6

              @Naveen_D

              In your regexp string.
              The '\' is a special mark. If u want to use it you have to type '\\'. This is the same situation if you want to use quote mark in your string. You have to type it like this '\"'.

              1 Reply Last reply
              0
              • N Naveen_D
                17 Aug 2017, 10:43

                @SGaist

                Don't forget to double the \ in your string.

                Sorry i didn't get in which string.

                M Offline
                M Offline
                m.sue
                wrote on 17 Aug 2017, 11:18 last edited by m.sue
                #7

                Hi @Naveen_D

                You can interactively test your expression on strings on a site like this: https://regex101.com/

                -Michael.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 17 Aug 2017, 11:51 last edited by
                  #8

                  To add to @m-sue, the QRegularExpression Example also provides a good tool to test and validate your regular expressions.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  8/8

                  17 Aug 2017, 11:51

                  • Login

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