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. [Solved] Qt regexp
Forum Updated to NodeBB v4.3 + New Features

[Solved] Qt regexp

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k 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.
  • M Offline
    M Offline
    moravas
    wrote on last edited by
    #1

    Hi People,

    I have a little bit problem with using of QRegExp class. Please consider the following dummy example:
    @
    QString str = "sadsfsdfg52151";
    QRegExp r("^([A-Za-Z]+)([0-9]+)");

    r.indexIn(str);
    
    qDebug() << r.cap(0);
    qDebug() << r.cap(1);
    qDebug() << r.cap(2);
    

    @

    I hope that those find full string via "cap(0)", the first part of "str" via "cap(1)" and the numbers at end of the string via "cap(2)", but it doesn't print anything. What I made wrong? :(
    Can anybody help me, how to write a properly regexp's with Qt?

    Regards,
    Norbert

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by JohanSolo
      #2

      Your syntax is wrong, the QRegExp should read:

      QRegExp r("^([A-Za-z]+)([0-9]+)");
      

      Note that the second 'z' is not written in caps any more.

      Disclaimer: tested with Perl only.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        You can also use:
        @QRegExp r("^([A-Za-z]+)(\d+)");@

        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