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);
Re: Regular Expression for Operators
Not sure what you mean, but what about using "OR" clauses, i.e. using | to separate sub patterns?
Cheers,
_
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);
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/
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 ?
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
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
Re: Regular Expression for Operators
Quote:
Originally Posted by
ChrisW67
Does
parulkalra14 ==
aaditya190? Do we have alter egos, two students working the same assignment or (diety forbid) commercial project?
Same IP :)