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. Parsing a QString using RegEX

Parsing a QString using RegEX

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

    I need to parse a QString for checking minimum number of digists in it and then need to take last 14 digits from the QString and convert them into QDate foramt. Below is my code that works for exact number of digits:
    @QString myString = "alpha20140402110241";
    QRegExp rx("(\d{14})");
    qDebug()<<"RegEx Result:" <<rx.cap(1);
    @

    How can I modify this code so that I can use this code for more 14 digits, in QString, as well?
    My RegEx should check for minimum 14 digits in my QString and only 14 digits. Afterwards , allow to me extract last 14 digits from QString using
    @rx.cap(1) @

    or any other method.

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #2

      hi
      try this..

      QString myString = "alpha20140402110241";

      QString res;

      for(int i = myString.length()-14 ; i < myString.length();i++)

      {

      res.append(myString.at(i));

      }

      qDebug() << res

      Output :

      20140402110241

      Be Cute

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        The syntax for "at least" is {14,}
        To extract only the last 14 characters you can use "QString::right()":http://qt-project.org/doc/qt-5/qstring.html#right

        Edit: @IamSumit copying characters one by one like that is very inefficient.

        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