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. Regular Expression not working!
Forum Updated to NodeBB v4.3 + New Features

Regular Expression not working!

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 2.7k 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.
  • siropS Offline
    siropS Offline
    sirop
    wrote on last edited by
    #2

    bq. Note: The C++ compiler transforms backslashes in strings. To include a \ in a regexp, enter it twice, i.e. \.

    http://qt-project.org/doc/qt-4.8/qregexp.html#characters-and-abbreviations-for-sets-of-characters

    To be, or not to be: that is the question:
    Whether ’tis nobler in the mind to suffer
    The slings and arrows of outrageous fortune,
    Or to take arms against a sea of troubles,
    And by opposing end them?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hadeus
      wrote on last edited by
      #3

      I had done that(forgot to mention here) ..still no result!!

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jazzco
        wrote on last edited by
        #4

        Can you pass your code example with a "text to be parsed"?

        1 Reply Last reply
        0
        • siropS Offline
          siropS Offline
          sirop
          wrote on last edited by
          #5

          Try
          @QStringList field = str.split(".(?![a-z])");@

          Maybe with \.

          To be, or not to be: that is the question:
          Whether ’tis nobler in the mind to suffer
          The slings and arrows of outrageous fortune,
          Or to take arms against a sea of troubles,
          And by opposing end them?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jazzco
            wrote on last edited by
            #6

            This way you are getting a string comparison. If you want the .split function to use a regular expression, you must pass a QRegExp:
            @QStringList field = str.split(QRegExp(".(?![a-z])"));@

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hadeus
              wrote on last edited by
              #7

              Yes I I appreciate your help, Sirop. But, I have already tried almost everything before posting here, and unfortunately nothing works. Here's my snippet :-
              QString st = "HELLO HOW ARE YOU.a THANK HOW YOU.2ELLO NOT YOU.";
              QStringList ql = st.split("\.(?![a-z])");
              qDebug()<< ql.at(0);

              OUTPUT: "HELLO HOW ARE YOU.a THANK HOW YOU.2ELLO NOT YOU"

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hadeus
                wrote on last edited by
                #8

                jazco let me try this..

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Hadeus
                  wrote on last edited by
                  #9

                  yeah jazzco yours works with double backslash! Thanks a ton, jazzco and sirop.

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

                    Hi,

                    Double backslashes are needed because you are still writing a string, so you need escape the backslash properly in order to obtain the correct regexp. You can test and validate regular expressions for QRegExp with the regular expression example from Qt's sources.

                    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
                    • H Offline
                      H Offline
                      Hadeus
                      wrote on last edited by
                      #11

                      Yes. I get that.

                      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