Results 1 to 7 of 7

Thread: Regular Expression for Operators

  1. #1
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Regular Expression for Operators

    Can we write a single code for all the operators instead of writing code for each and every operator?
    This code is working but i want single regular Expression for all operators
    plus.setForeground(Qt::red);
    rule.pattern = QRegExp("\\+"); // for plus
    rule.format = plus;
    highlightingRules.append(rule);

    minus.setForeground(Qt::red);
    rule.pattern = QRegExp("\\-");
    rule.format = minus; // for minus
    highlightingRules.append(rule);


    mul.setForeground(Qt::red);
    rule.pattern = QRegExp("\\*");
    rule.format = mul; // for multiply
    highlightingRules.append(rule);


    div.setForeground(Qt::red);
    rule.pattern = QRegExp("/");
    rule.format = div; // for division
    highlightingRules.append(rule);

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Regular Expression for Operators

    Not sure what you mean, but what about using "OR" clauses, i.e. using | to separate sub patterns?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    parulkalra14 (14th January 2014)

  4. #3
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Regular Expression for Operators

    @anda_skoa Sir : This code is working thanku so much.but actually, I want whenever these operators appears in between double quotes like: " + ", + operator should be in blue color and whenever these operators appears in an expression i.e a=b+c, then + should be red color. But problem comes whenever i write both these codes together in the same program then operators in between double quotes appears in red instead of blue.Can you provide me some code related to this problem?
    quotationFormat.setForeground(Qt::blue);
    rule.pattern = QRegExp("\".*\"");
    rule.format = quotationFormat; // for double quotes
    highlightingRules.append(rule);

    operators.setForeground(Qt::red);
    rule.pattern = QRegExp("\\+|\\-|\\/|\\*");
    rule.format = operators;
    highlightingRules.append(rule);

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Regular Expression for Operators

    Well, if you have one regex matching an expression that is part of a larger expression matched by a different regex, than you need to care about the order in which you apply your rules.

    Cheers,
    _

    P.S.: if you are doing syntax highlighting make sure you had a look at Kate's syntax highlighting files. Those are also used by Qt creator for example.
    http://kate-editor.org/2005/03/24/wr...lighting-file/

  6. The following user says thank you to anda_skoa for this useful post:

    parulkalra14 (7th January 2014)

  7. #5
    Join Date
    Nov 2013
    Posts
    46
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Regular Expression for Operators

    @anda_soka: Its working now...Thanks alot....


    Added after 47 minutes:


    I have one more query, only few colors are supported by Qt For eg: if I would like to use orange color then what will be the code for that ?
    Last edited by parulkalra14; 7th January 2014 at 06:46.

  8. #6
    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: Regular Expression for Operators

    This thread bears a striking resemblance to this thread, the end of this thread and some others by aaditya190.

    Does parulkalra14 == aaditya190? Do we have alter egos, two students working the same assignment or (diety forbid) commercial project?



    Added after 4 minutes:


    Quote Originally Posted by parulkalra14 View Post
    I have one more query, only few colors are supported by Qt For eg: if I would like to use orange color then what will be the code for that ?
    QTextCharFormat, QTextFormat, QBrush and QColor
    Qt Assistant is your friend
    Last edited by ChrisW67; 7th January 2014 at 08:29.

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

    Default Re: Regular Expression for Operators

    Quote Originally Posted by ChrisW67 View Post
    Does parulkalra14 == aaditya190? Do we have alter egos, two students working the same assignment or (diety forbid) commercial project?
    Same IP
    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.


Similar Threads

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

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
  •  
Qt is a trademark of The Qt Company.