Results 1 to 9 of 9

Thread: Define a QRegExp

  1. #1
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Define a QRegExp

    Is there a way to define a QRegExp that would contain {}... e.g there is a regular expression defined as QRegExp rx("\\b[a-z]"); for characters a-z. Can we do it for only {} as well? If yes, can anyone help me with some code?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Define a QRegExp

    What have you tried so far ?

  3. #3
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Define a QRegExp

    I have tried something like this... QRegExp rx("\\b{}");.. but this is now working. Can you suggest me the right way to do this as i want to include curly braces {} as a part of rx...

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Define a QRegExp

    (...) include curly braces {} as a part of rx..
    So there should be something between those brackets, right ? Your regexp captures only expressions starting with curly brackets (exps like "{}", "{}whatever",...).
    Can you give some examples of what you want to capture with this regexp ?

  5. #5
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Define a QRegExp

    Like i have tried some examples.. to include characters A-Z, i used QRegExp rx("\\b{A-Z}");.. this works.. What i want to know is what shall i do to include curly braces {} also as a part of the expression? Whatever we write in {} is included in the expression.. What to write to include {} as a part of the expression??

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Define a QRegExp

    Sorry my previous post was wrong - curly brackets are special characters used when you want to define a number of occurences of an expression, so in order to match them, you have to use backslash:
    Qt Code:
    1. QRegExp rx("\\{(\\w|\\s)+\\}");
    2. qDebug() << rx.indexIn("{this one}") << rx.indexIn("not this one");
    To copy to clipboard, switch view to plain text mode 
    Sorry I totally forgot about this.

  7. #7
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Define a QRegExp

    Thanks for the reply.. But this piece of code is also not working..
    Instead i tried this .. QRegExp rx("\\{()+\\}");.. This worked.. When it encounters simultaneous {}, it works. What i want to do is to make individual curly braces i.e { and } work independently. Can you help me with this?
    Last edited by aaditya190; 29th November 2013 at 16:49.

  8. #8
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Define a QRegExp

    But this piece of code is also not working..
    This regular expression works without problems - it all depends on what you want to capture.
    What i want to do is to make individual curly braces i.e { and } work independently.
    Use \\{ to match {, and \\} to match }. What else do you need ?

  9. #9
    Join Date
    Nov 2013
    Location
    Chandigarh, India
    Posts
    62
    Thanks
    8
    Thanked 11 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Define a QRegExp

    It worked.. Thank You very much....

Similar Threads

  1. Does not define type
    By Atomic_Sheep in forum General Programming
    Replies: 4
    Last Post: 22nd July 2013, 15:04
  2. how can I Define whole control styles ?
    By hcetiner in forum Newbie
    Replies: 2
    Last Post: 12th April 2010, 10:49
  3. tr with #define..it can work?
    By mattia in forum Newbie
    Replies: 9
    Last Post: 4th February 2008, 11:15
  4. #define MYCLASS_H ?
    By bnilsson in forum General Programming
    Replies: 1
    Last Post: 3rd February 2008, 10:50
  5. where should i put #define in QtDesigner?
    By nass in forum Qt Tools
    Replies: 1
    Last Post: 16th October 2006, 15:52

Tags for this Thread

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.