Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] QRegExp doesn't match strings

    General and Desktop
    2
    6
    1471
    Loading More Posts
    • 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
      Magnum last edited by

      Hello:

      I want a regular expression able to catch strings that start with a pair of repeated letters so I wrote the following:

      @QRegExp beginWithPair("^(\w)\1+");@

      As far as I know It should match this string:

      bq. aaarfads

      and It doesn't.

      What am I doing wrong?

      Thanks

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        What output do you expect ? And what do you get ?

        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 Reply Quote 0
        • M
          Magnum last edited by

          When I use

          @QRegExp::exactMatch ( const QString & str ) const@

          I always get false.

          I tried here and It worked:

          http://www.rubular.com/

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Have a look at the documentation of exactMatch. Your string doesn't match exactly your regexp. If it was "aa" it would.

            You should rather use indexIn

            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 Reply Quote 0
            • M
              Magnum last edited by

              You're right.

              Thank you.

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                You're welcome !

                Don't forget to update the thread's title by prepending solved so other forum users may know a solution has been found :)

                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 Reply Quote 0
                • First post
                  Last post