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

Re: Regular exp

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 4 Posters 1.7k Views 2 Watching
  • 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.
  • Naveen_DN Offline
    Naveen_DN Offline
    Naveen_D
    wrote on 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.sueM 1 Reply Last reply
    0
    • Naveen_DN Naveen_D

      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.sueM Offline
      m.sueM Offline
      m.sue
      wrote on 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.

      Naveen_DN 1 Reply Last reply
      0
      • m.sueM m.sue

        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.

        Naveen_DN Offline
        Naveen_DN Offline
        Naveen_D
        wrote on 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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

          Naveen_DN 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

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

            Naveen_DN Offline
            Naveen_DN Offline
            Naveen_D
            wrote on 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.sueM 1 Reply Last reply
            0
            • K Offline
              K Offline
              Kaluss
              wrote on 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
              • Naveen_DN Naveen_D

                @SGaist

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

                Sorry i didn't get in which string.

                m.sueM Offline
                m.sueM Offline
                m.sue
                wrote on 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
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 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

                  • Login

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