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. Need help with a QRegExp.

Need help with a QRegExp.

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

    Hi,

    can somebody help me to solve my regex mistake.

    I have the following string (and more like that):
    NAME=......,

    Know I want to extract the part between = and ,
    in the party between = and , can be any character (but no = or ,)

    I have tried something like that (I know its terrible):
    @[^=][^,]
    [^=^,]
    @

    Thx.

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

      Hi,

      This is more a regexp than a Qt problem but:

      Do you know exactly the type of characters you will get before and after the = sign ?
      Can they be empty ?

      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
      • G Offline
        G Offline
        gandiii
        wrote on last edited by
        #3

        before the =, the characters should normaly be from A to Z.
        And after the = they can be every character (by the NAME if they use some cyrillic names)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Alek Śmierciak
          wrote on last edited by
          #4

          Are you sure that using regular expressions here is a good idea? Seems that what you need is a substring beginning at the equals sign and ending just before the last sign.

          Use "QString::mid":http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#mid function to get the substring between '=' and ','. To get the position of '=', provided it changes because of different NAMEs, use "QString::indexOf":http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#indexOf function.

          The result would look similar to that:

          @ QString line = "NAME=........,";
          QString part = line.mid(line.indexOf("=") + 1, line.length() - line.indexOf("=") - 1); @

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gandiii
            wrote on last edited by
            #5

            thank you,
            i will give it a try.

            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