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);
    		text.replace(expDate,"DATE");
    	}else{
    		qDebug()<< "database::checkCodeExp notFound" << text << " regExp: "<< expDate.pattern();
    	}
    

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


  • Qt Champions 2016

    @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
 

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