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. Strings fields *,?
Forum Update on Monday, May 27th 2025

Strings fields *,?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 2.2k 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.
  • D Offline
    D Offline
    devfeel
    wrote on last edited by
    #1

    Hi
    qString str="Hi my name is Dave, I am using Qt to do my project."

    Can I use some thing like * or ?
    hi my name is ?, I am using ? to do my project.

    This should give me Dave and Qt. Something like string Template match.
    Please guide.
    Thank you

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Hi! If i understand you correctly, you can use "QRegExp":http://qt-project.org/doc/qt-4.8/qregexp.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        devfeel
        wrote on last edited by
        #3

        Thanks qxoz..But in that reference page there is only regarding file matching like *.html etc. how to pass with my string and get values.
        Can u please provide some snippet or any other reference.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          It does not matter whether a string contains a filename or a sentence, the principle is the same.

          There are plenty of regular expression tutorials around with examples and all. Just use google. RegExps are something that should be in every programmers toolbox, so learning about them will not be a waste of time!

          1 Reply Last reply
          0
          • D Offline
            D Offline
            devfeel
            wrote on last edited by
            #5

            Hi all...I used this..but not working...tried some others like * , \W* etc
            @QString str="my name is dave";
            QRegExp rx("my name is [^ ]*");
            rx.setPatternSyntax(QRegExp::Wildcard);
            int pos = 0;
            while ((pos = rx.indexIn(str, pos)) != -1) {
            qDebug()<< rx.capturedTexts();

            qDebug() << rx.cap(1);
            pos += rx.matchedLength();
            }
            @
            Whats wrong...Please help

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

              Hi,

              AFAIK, you don't use a capturing RegExp, you have to use parenthesis to capture something. Take a look at the QRegExp doc, specially the "capturing text part":http://qt-project.org/doc/qt-4.8/qregexp.html#capturing-text

              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
              • D Offline
                D Offline
                devfeel
                wrote on last edited by
                #7

                the string read from the file is below
                reject tcp any any -> any any (content:"twitter.com";msg:"TWITTER1 BEING ACESSED";sid:41325;rev:001;)
                [CODE]
                QRegExp re("(\w*) tcp (\w*) any -> any any \(content:(("([A-Za-z0-9_\./\-$\s])"));msg:(("([A-Za-z0-9_\./\-$\s])"));sid:(\w*);");

                while((pos=re.indexIn(str, pos))!=-1){

                        list << re.cap(1);//gives first field from string
                        list << re.cap(2);//gives 3rd field
                        list << re.cap(3);//gives content
                        list << re.cap(6);//gives msg
                        list << re.cap(9);//gives sid
                
                        pos+=re.matchedLength();
                
                    }
                

                [/CODE]
                The above regex gives me reject, any, twitter.com, twitter being accessed, 41325
                but for that i have to choose 1,2,3,6,9 fields out of the re.cap coz the line has multiple line of quotes.

                but the same doesn't work for the below string
                alert tcp 192.168.1.9 any -> any any (content:"www.gmail.com";msg:"gmail being ACCESSED";sid:41330;rev:001;)

                please help

                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