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. QRegExp not found
QtWS25 Last Chance

QRegExp not found

Scheduled Pinned Locked Moved Solved General and Desktop
qregexp
3 Posts 2 Posters 3.2k 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.
  • cfdevC Offline
    cfdevC Offline
    cfdev
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • cfdevC Offline
        cfdevC Offline
        cfdev
        wrote on last edited by cfdev
        #3

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

        Ok I found the solution with this regular expression:

        QRegExp regex("\\<date(:(.*))?\\>");
        
        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