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. QRegularExpressionMatch A:B/C to A,B,C
Forum Updated to NodeBB v4.3 + New Features

QRegularExpressionMatch A:B/C to A,B,C

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 481 Views 1 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    A:B/C to A,B,C

    QString location = "192.168.2.101:1068/description.xml";
    QRegularExpression RE("(:*)(/*)");
    QRegularExpressionMatch REM = RE.match(location);
    QString IP = REM.captured(0);
    QString port = REM.captured(1);
    QString description = REM.captured(2);
    

    IP = "192.168.2.101"
    port = "1068"
    description = "description.xml"

    https://github.com/sonichy

    eyllanescE JonBJ 2 Replies Last reply
    0
    • sonichyS sonichy

      A:B/C to A,B,C

      QString location = "192.168.2.101:1068/description.xml";
      QRegularExpression RE("(:*)(/*)");
      QRegularExpressionMatch REM = RE.match(location);
      QString IP = REM.captured(0);
      QString port = REM.captured(1);
      QString description = REM.captured(2);
      

      IP = "192.168.2.101"
      port = "1068"
      description = "description.xml"

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @sonichy Why is regex necessary? I see that it is enough to use QString::split() 2 times: the first with ":" and the second with "/".

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      2
      • sonichyS sonichy

        A:B/C to A,B,C

        QString location = "192.168.2.101:1068/description.xml";
        QRegularExpression RE("(:*)(/*)");
        QRegularExpressionMatch REM = RE.match(location);
        QString IP = REM.captured(0);
        QString port = REM.captured(1);
        QString description = REM.captured(2);
        

        IP = "192.168.2.101"
        port = "1068"
        description = "description.xml"

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @sonichy
        You could do it in two statements as @eyllanesc wrote. (Though it won't cope so easily if, say, the filename part is allowed to be a path with multiple /s, which I assume it could be.) I would probably do it with a regular expression, but you want 3 captured elements and your reg ex only calls for 2. It's really very simple. I would go something like (untested):

        QRegularExpression RE("([^:]*):([^/]*)/(.*)");
        
        sonichyS 1 Reply Last reply
        2
        • JonBJ JonB

          @sonichy
          You could do it in two statements as @eyllanesc wrote. (Though it won't cope so easily if, say, the filename part is allowed to be a path with multiple /s, which I assume it could be.) I would probably do it with a regular expression, but you want 3 captured elements and your reg ex only calls for 2. It's really very simple. I would go something like (untested):

          QRegularExpression RE("([^:]*):([^/]*)/(.*)");
          
          sonichyS Offline
          sonichyS Offline
          sonichy
          wrote on last edited by sonichy
          #4

          @JonB
          "192.168.2.104:1068/description.xml"
          "192.168.2.104"
          "1068"

          Code should change to this:

          QString IP = REM.captured(1);
          QString port = REM.captured(2);
          QString description = REM.captured(3);
          

          Acturally, my full line is:
          LOCATION: http://192.168.2.104:1068/description.xml
          How to Match ?

          https://github.com/sonichy

          JonBJ jeremy_kJ 2 Replies Last reply
          0
          • sonichyS sonichy

            @JonB
            "192.168.2.104:1068/description.xml"
            "192.168.2.104"
            "1068"

            Code should change to this:

            QString IP = REM.captured(1);
            QString port = REM.captured(2);
            QString description = REM.captured(3);
            

            Acturally, my full line is:
            LOCATION: http://192.168.2.104:1068/description.xml
            How to Match ?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @sonichy
            Depends what ranges of input you need to cover. For the string you show what about:

            "[^/]*//([^:]*):([^/]*)/(.*)"

            1 Reply Last reply
            0
            • sonichyS sonichy

              @JonB
              "192.168.2.104:1068/description.xml"
              "192.168.2.104"
              "1068"

              Code should change to this:

              QString IP = REM.captured(1);
              QString port = REM.captured(2);
              QString description = REM.captured(3);
              

              Acturally, my full line is:
              LOCATION: http://192.168.2.104:1068/description.xml
              How to Match ?

              jeremy_kJ Offline
              jeremy_kJ Offline
              jeremy_k
              wrote on last edited by
              #6

              @sonichy said in QRegularExpressionMatch A:B/C to A,B,C:

              Acturally, my full line is:
              LOCATION: http://192.168.2.104:1068/description.xml
              How to Match ?

              QUrl implements url parsing and provides access to the host, port, and file name among other things.

              Asking a question about code? http://eel.is/iso-c++/testcase/

              1 Reply Last reply
              1

              • Login

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