Nominate our 2022 Qt Champions!

QRegExp not found

  • Hi all,
    I try to use QRegExp to find and replace text with this code:

        QString text = "FC<date:yyMM><index>";
    	QRegExp expDate( "<date:(.*?)>" ); 
    	pos = expDate.indexIn( text );
    	if (pos > -1) {
    		qDebug()<< "database::checkCodeExp" << expDate.cap(1) << " " <<  expDate.cap(2);
    		qDebug()<< "database::checkCodeExp notFound" << text << " regExp: "<< expDate.pattern();

    This expression "date:(.*?)" works with the tester php
    What am I doing wrong ?

  • Moderators

    @cfdev said:
    Isn't (.*?) the same as (.*)? It looks that way to me. If you're using Qt5 do consider using the replacement(s) for QRegExp - QRegularExpression which is perl compatible.

  • not the same (.*?) and (.*) I tested on QT4 and QT5

    Ok I found the solution with this regular expression:

    QRegExp regex("\\<date(:(.*))?\\>");

Log in to reply