Results 1 to 4 of 4

Thread: QRegExp not matching the { character !!

  1. #1
    Join Date
    Feb 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default QRegExp not matching the { character !!

    Hello,

    I am trying to match a string within {STRING}.

    i tried using the following code:
    Qt Code:
    1. QRegExp exp("\{.*\}");
    To copy to clipboard, switch view to plain text mode 

    and i even tried it for a specific word that i know exists, like:
    Qt Code:
    1. QRegExp exp("\{file\}");
    To copy to clipboard, switch view to plain text mode 

    and i also tried:
    Qt Code:
    1. QRegExp exp("\\{file\\}");
    To copy to clipboard, switch view to plain text mode 

    non of these worked, any ideas on how to do this ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QRegExp not matching the { character !!

    Seems to work fine for me...

    Qt Code:
    1. #include <QtCore>
    2.  
    3. int main() {
    4. QRegExp rx("\\{.*\\}");
    5. QString str = "bla {xxx} bla";
    6. qDebug() << rx.indexIn(str);
    7. return 0;
    8. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QRegExp not matching the { character !!

    I'm not sure what you're trying to accomplish with the curly braces, but Qt RegExps use them as numeric quantifiers; see the documentation at http://doc.qt.nokia.com/4.5/qregexp.html

    There are several different systems of regular expressions, each with its own peculiar syntax. The syntax is not interchangeable, and you need to know which you are using, particularly when venturing beyond the most basic expressions.

  4. #4
    Join Date
    Feb 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QRegExp not matching the { character !!

    thanks wysota, it worked perfect.

    i guess the problem was me using this:
    Qt Code:
    1. str.indexOf(rx);
    To copy to clipboard, switch view to plain text mode 

    the index is always -1.

Similar Threads

  1. QRegExp Unicode Character Classes
    By Delagen in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2010, 13:17
  2. Matching HTML tags
    By pucara_faa in forum Qt Programming
    Replies: 4
    Last Post: 22nd January 2010, 14:19
  3. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 16:28
  4. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 12:25
  5. QRegExp: too big for character
    By ucomesdag in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2007, 20:52

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.