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. An one liner to unpack QRegularExpressionMatch results into multiple variable?

An one liner to unpack QRegularExpressionMatch results into multiple variable?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qregularexpress
6 Posts 4 Posters 669 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.
  • L Offline
    L Offline
    lansing
    wrote on 20 Jul 2020, 11:09 last edited by
    #1

    I have a QRegularExpression object that captures multiple groups from strings, and a QRegularExpressionMatch::capture(n) to split them out individually.

    Is there an one liner like in python where I can unpack them all at once like this instead of one at a time?

    [id, name, type, text] = infoREMatch.capture();
    
    J J 2 Replies Last reply 20 Jul 2020, 12:48
    0
    • L lansing
      20 Jul 2020, 11:09

      I have a QRegularExpression object that captures multiple groups from strings, and a QRegularExpressionMatch::capture(n) to split them out individually.

      Is there an one liner like in python where I can unpack them all at once like this instead of one at a time?

      [id, name, type, text] = infoREMatch.capture();
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 20 Jul 2020, 12:48 last edited by
      #2

      @lansing said in An one liner to unpack QRegularExpressionMatch results into multiple variable?:

      Is there an one liner like in python where I can unpack them all at once

      No, there is not

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • L lansing
        20 Jul 2020, 11:09

        I have a QRegularExpression object that captures multiple groups from strings, and a QRegularExpressionMatch::capture(n) to split them out individually.

        Is there an one liner like in python where I can unpack them all at once like this instead of one at a time?

        [id, name, type, text] = infoREMatch.capture();
        
        J Offline
        J Offline
        JonB
        wrote on 20 Jul 2020, 12:54 last edited by
        #3

        @lansing
        The closest is QStringList QRegularExpressionMatch::capturedTexts() const.

        L 1 Reply Last reply 20 Jul 2020, 14:20
        1
        • J JonB
          20 Jul 2020, 12:54

          @lansing
          The closest is QStringList QRegularExpressionMatch::capturedTexts() const.

          L Offline
          L Offline
          lansing
          wrote on 20 Jul 2020, 14:20 last edited by
          #4

          @JonB

          I was using this one now, it's a little bit better in mass control like trimming all elements at once. But still it couldn't be unpack.

          J 1 Reply Last reply 20 Jul 2020, 14:52
          0
          • L lansing
            20 Jul 2020, 14:20

            @JonB

            I was using this one now, it's a little bit better in mass control like trimming all elements at once. But still it couldn't be unpack.

            J Offline
            J Offline
            JonB
            wrote on 20 Jul 2020, 14:52 last edited by
            #5

            @lansing said in An one liner to unpack QRegularExpressionMatch results into multiple variable?:

            But still it couldn't be unpack.

            ? In C++ it's like a one-line function wrapper. Yes, C++ isn't the same as Python. Thank goodness! Use Python + PySide2/PyQt5 if you prefer what you can do there over C++.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fcarney
              wrote on 20 Jul 2020, 14:58 last edited by
              #6

              You could write a wrapper that returns tuples and use tie to place in separate vars:
              https://www.geeksforgeeks.org/how-to-return-multiple-values-from-a-function-in-c-or-cpp/
              Scroll to the tuple example. Yes Python has some nice things. I would really love comprehensions in C++.

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              2

              4/6

              20 Jul 2020, 14:20

              • Login

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