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. [Solved] Problem with QRegExp
Forum Update on Monday, May 27th 2025

[Solved] Problem with QRegExp

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.5k 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.
  • M Offline
    M Offline
    mbertschi
    wrote on last edited by
    #1

    I am trying to use QRegExp to validate a string whether it only contains printable ASCII characters:

    @QRegExp regex("(^[\\40-\\176]{1,47}$)");//Printable ASCII characters only
    if(regex.exactMatch(value))
    {
    appName = value;
    }@

    The problem is that the above Regular Expression (^[\40-\176]{1,47}$) is working as expected with "Expresso":http://www.codeproject.com/Articles/3669/Expresso-A-Tool-for-Building-and-Testing-Regular-E but not with QRegExp. I have also tested it with the .Net Regex class (System.Text.RegularExpression) and it works there, too. I'm not really familiar with QRegExp yet and hope someone might be able to help me.

    cheers,
    Marco

    Edit: Thanks to SGaist who helped me solving my problem - The solution was to replace QRegExp with QRegularExpression, as described at "CodeProject":http://www.codeproject.com/Tips/729656/Reasons-to-abandon-and-replace-QRegExp-in-your-Qt

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

      Hi and welcome to devnet,

      To test/build your RegExps with Qt you have the QRegExp example in example/widgets/tools/regexp that can help

      Also if you are using Qt 5 please consider moving to QRegularExpression

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

        Dear SGaist,

        thank you for your suggestion to move to QRegularExpression, it indeed fixed the issue. I did some reading on QRegExp and QRegularExpression - I assume QRegularExpression is using a better RegEx engine than QRegExp did?

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

          Yes it does.

          QRegularExpression implements Perl-compatible regular expressions.

          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
          • M Offline
            M Offline
            mbertschi
            wrote on last edited by
            #5

            Alright, thank you very much.
            I did a quick writeup on my issue since I think that I'm not going to be the only one facing the very same issue.
            Have "a look at it":http://www.codeproject.com/Tips/729656/Reasons-to-abandon-and-replace-QRegExp, if you want to.

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

              You're welcome !

              Interesting article :)

              Since you have it working now, please update the thread title 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
              0
              • M Offline
                M Offline
                mbertschi
                wrote on last edited by
                #7

                The thread title is updated, and so is the question which now contains a small summary of the solution at its bottom.

                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