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?
QtWS25 Last Chance

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 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();
    
    jsulmJ JonBJ 2 Replies Last reply
    0
    • L lansing

      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();
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

        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();
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

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

        L 1 Reply Last reply
        1
        • JonBJ JonB

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

          L Offline
          L Offline
          lansing
          wrote on 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.

          JonBJ 1 Reply Last reply
          0
          • L lansing

            @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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on 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

              • Login

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