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. Choose between QRegExp or boost regular expressions?

Choose between QRegExp or boost regular expressions?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 6.3k 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.
  • F Offline
    F Offline
    Flurite
    wrote on last edited by
    #1

    Sorry for the bump of this post, but would you suggest using the QRegExp Library or the Boost library for regular expressions/parsing?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      [I've split your question off to a separate thread, as it was only loosely related to the original one, Volker]

      There is no definite answer to this question (as to almost ever programming related question). It depends on the features you need for your regexp and your willingness to add another library.

      Some hints for taking the decision:

      • If QRegExp fits your need, go with it. If it doesn't but boost does, go with boost.
      • If it's hard to add another library (probably for that regexp thingy only), stick with Qt.
      • If you run into performance issues with QRegExp, consider boost. But that can be measured only in your real world application or some test scenario that resembles your real world app. Guessing will most probably lead you to false decisions.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Flurite
        wrote on last edited by
        #3

        Do both have the same capabilities?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          To my knowledge, QRegExp has some limitations and does not support all that, for example, preg provides. I don't know boost regexp, so I cannot compare those two.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Flurite
            wrote on last edited by
            #5

            bq. To my knowledge, QRegExp has some limitations and does not support all that, for example, preg provides. I don’t know boost regexp, so I cannot compare those two.

            Alright, I guess I'll play around with QRegExp for now.. but I do have another question about capturing strings of text. It seems that before using the cap() function, it is MANDATORY that you call the indexIn() function for some reason.

            For example, this works:

            @void captures()
            {
            QString testString1("OMG"); QRegExp acronym("([A-Z]{1,})");
            acronym.indexIn(testString1);

            cout << (acronym.cap(1)).toStdString() << "\n\n";
            

            }@

            but this doesn't..

            @void captures()
            {
            QString testString1("OMG"); QRegExp acronym("([A-Z]{1,})");

            cout << (acronym.cap(1)).toStdString() << "\n\n";
            

            }@

            Does anyone know why?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

              How should the second version give any result? acronym never got in touch with testString, how should it know about its contents? You could even remove the testString definition completely and don't get a compiler error!

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Flurite
                wrote on last edited by
                #7

                bq. How should the second version give any result? acronym never got in touch with testString, how should it know about its contents? You could even remove the testString definition completely and don’t get a compiler error!

                Silly me.. is there a specific function that connects the regular expression to the string?

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  Yes, QRegExp::indexIn() ;-)

                  In addition, you might use QRegExp::exactMatch() if you just want to match and you do not need any capture groups.

                  As to your actual question: keep in mind that Qt probably requires you to use QRegExp instead of any other third-party implementation, for example when using QRegExpValidator. If you just do plain pattern matching stick to Volkers advice and benchmark first. If there is no bottleneck go stick with Qt, as this means one worry less.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    If you are considdering using a different library, I would seriously considder using PCRE. The reason is that this is the library that will be used in Qt 5's new QRegularExpression & friends. If you use the same underlying library, you will likely experience less issues with porting over your expressions to the new framework when you decide to switch.

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      ixSci
                      wrote on last edited by
                      #10

                      boost regexp is much better than Qt one because it is PCRE compliant and QRegExp is not.
                      But you have even better option: just use state of the art compiler and use std::regexp since it is part of the C++11 standard.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        While being PCRE compliant is a good point in favor of boost or std::regexp, it is not the killer argument that kicks QRegExp out of the game. Experience taught me that one gets to the limits of QRegExp and need to switch implementations only seldom. I personally never reached it.

                        So if your regular expressions are more or less "standard" (in the sense of "simple") one surely can profit from the integration of QRegExp with the rest of the Qt ecosystem (QString!)

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        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