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. QRegularExpression and named capture groups
Qt 6.11 is out! See what's new in the release blog

QRegularExpression and named capture groups

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 3.9k 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.
  • J Offline
    J Offline
    jkdoug
    wrote on last edited by
    #1

    I would like to see a method for retrieving the names of the capture groups as well as the text captured by them. I want to pass all the captured texts to a Lua table, both numbered and named. I'm not sure how to request a feature in Qt properly, so I hope this is an okay place to start.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      You would ask in the Qt Bug tracker.
      https://bugreports.qt-project.org/secure/Dashboard.jspa

      You should search to see if someone else is already requesting this. If you can, provide a small, compilable program that demonstrates what you wish to achieve and why it cannot be achieved with the class as-is.

      1 Reply Last reply
      0
      • W Offline
        W Offline
        warjan
        wrote on last edited by
        #3

        Couldn't you do this using QRegularExpressionMatch::capturedTexts()? There might be problems with named capture groups of course, but you can store them in list and supply them to regex, right?
        "http://qt-project.org/doc/qt-5.0/qtcore/qregularexpressionmatch.html#capturedTexts":http://qt-project.org/doc/qt-5.0/qtcore/qregularexpressionmatch.html#capturedTexts

        Does your grass is really that greener?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          [quote author="warjan" date="1357571186"]Couldn't you do this using QRegularExpressionMatch::capturedTexts()?[/quote]

          -From my understanding he wants the pattern of the group, not the matched string.-
          -so in a regex "test(\d+)test" he literally wants "\d+". Which will be tough if you don't want to reimplement a regex engine. (think "test(\d+(\w)?)*test" or worse stuff)-
          I think I got that wrong. Disregard what I said.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jkdoug
            wrote on last edited by
            #5

            In the pattern "test(?<first>\d+)test" I want to know that "first" is the name of the capture group. QRegularExpression or QRegularExpressionMatch just need to provide a key/value map for capture groups instead of assuming they are numerically indexed or that you know the names of the groups in advance.

            Thank you for the bug report advice. I will look into that now!

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dangelog
              wrote on last edited by
              #6

              Hi,

              please review :-) https://codereview.qt-project.org/#change,45265

              Software Engineer
              KDAB (UK) Ltd., a KDAB Group company

              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