Use regex within C++ program



  • Hello to all,

    I have to add a GUI to a C++ program that I'm working on. I'm trying to use regex in the C++ program, but I've found
    that only Microsoft Visual Studio 2012 compiler supports Regex for C++.

    Should I do the C++ code in MSVisual Studio and once finish use my C++ source code to add the GUI in Qt or how can I do?

    Thanks in advance for the answer.



  • You can use the QRegExp class!
    And by using it, you gain portability at no extra cost! =D



  • Hello Evellyn,

    Thanks for your answer.

    I'm new to Qt and I'd like to know if having my current C++ code I can do something like below:

    My code looks like this and whithin while loop is where I need to a call to a function to parse a string using regex .

    So, can I include the QRegExp code inside my C++ code or the QRegExp code should go in another file and I need to call QRegExp function from C++ code? if yes, how?

    @#include <iostream>
    .
    .
    function1 ()
    //My original C++ code

    function2 (){
    //My original C++ code
    }

    My_RegexFunction(Input) {
    // Qt QRegExp code

    }

    int main () {
    .
    ..
    //My original C++ code

    while () {

    Myvar=My_RegexFunction(Input);
    }
    }@

    Thanks in advance for the help.


  • Lifetime Qt Champion

    You can use QRegExp directly in your code, have a look "at the documentation":http://qt-project.org/doc/qt-4.8/qregexp.html#details to see how to use it.


  • Moderators

    if you use Qt 5 i would suggest to use "QRegularExpression":http://qt-project.org/doc/qt-5.0/qtcore/qregularexpression.html rather than QRegExp.
    Since QRegExp is buggy and not complete and not maintained anymore.
    QRegularExpression in contrary is a implementation of full Perl-compatible regular expressions in Qt.



  • Hello SGaist and raven-worx,

    Thank you for your answers. I'll check the options you suggest me.

    Best regards


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.