Results 1 to 3 of 3

Thread: QRegExp for syntax highlight

  1. #1
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QRegExp for syntax highlight

    Hi,
    I am trying to write a regexp for syntax highlighter to capture only numbers in a text like [12]. So I need to find a number in brackets but I don't need brackets to be captured. Any suggestions?

  2. #2
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QRegExp for syntax highlight

    This should work :
    Qt Code:
    1. QString str("test 15[12]dlfk.[dsf[65]");
    2. qDebug() << str;
    3. QRegExp regExp("\\[(\\d+)\\]");
    4. int pos= 0;
    5. while( (pos = regExp.indexIn(str, pos)) != -1)
    6. {
    7. qDebug() << "Found " << regExp.cap(1);
    8. pos += regExp.matchedLength();
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QRegExp for syntax highlight

    Tnx, I just hoped that that could be done without cap.

Similar Threads

  1. .pro file syntax
    By lxman in forum Qt Tools
    Replies: 4
    Last Post: 11th February 2011, 23:21
  2. Regarding syntax
    By Yayati.Ekbote in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2010, 14:15
  3. QListWidget syntax highlight
    By Ken_Afford in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2010, 15:54
  4. Odd Syntax
    By acxdotfm in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2008, 20:23
  5. Syntax highlight selection problem
    By s.toonen in forum Qt Programming
    Replies: 9
    Last Post: 4th June 2008, 12:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.