Results 1 to 3 of 3

Thread: Defining a regular expression containing double quotes

  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 Defining a regular expression containing double quotes

    I have defined a regular expression for double quotes i.e whatever comes in "" gets some format..using qtextcharformat..and one expression for operator +.. like
    Qt Code:
    1. QRegExp rx1("\".*\"");
    2. QRegExp rx2("\\+");
    3. rx1.setForeground((QColor::red));
    4. rx2.setForeground((QColor::orange));
    To copy to clipboard, switch view to plain text mode 

    The problem i am facing is that if i type + inside double quotes, it doesn't get the format i defined for "" i.e it retains its orange color instead should be red only as written inside "". Can anyone suggest me what wrong I am doing?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Defining a regular expression containing double quotes

    Your code will not even compile. If you are going to post code at least copy and paste it from something that compiles (unless the question is why doesn't this compile?)

    I assume you mean something like :
    Qt Code:
    1. QString value("\"+\"");
    2. QRegExp rx1("\".*\"");
    3. QRegExp rx2("\\+");
    4. if (rx1.indexIn(value) != -1)
    5. someUnspecifiedObject.setForeground((QColor::red));
    6. if (rx2.indexIn(value) != -1)
    7. someUnspecifiedObject.setForeground((QColor::orange));
    To copy to clipboard, switch view to plain text mode 
    Both regular expressions match the string, "+", and both colours are applied in order.

  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: Defining a regular expression containing double quotes

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

Similar Threads

  1. Regular expression
    By aguleo in forum Newbie
    Replies: 0
    Last Post: 25th January 2013, 16:00
  2. Regular expression
    By QFreeCamellia in forum Newbie
    Replies: 8
    Last Post: 30th December 2011, 23:34
  3. Regular expression help!
    By ConkerX in forum Qt Programming
    Replies: 10
    Last Post: 31st August 2011, 16:47
  4. Help with regular expression
    By Gourmet in forum General Programming
    Replies: 19
    Last Post: 11th August 2011, 16:04
  5. Find with Regular Expression?
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2007, 15:44

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.