PDA

View Full Version : Defining a regular expression containing double quotes



aaditya190
4th December 2013, 11:15
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


QRegExp rx1("\".*\"");
QRegExp rx2("\\+");
rx1.setForeground((QColor::red));
rx2.setForeground((QColor::orange));


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?

ChrisW67
4th December 2013, 12:50
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 :


QString value("\"+\"");
QRegExp rx1("\".*\"");
QRegExp rx2("\\+");
if (rx1.indexIn(value) != -1)
someUnspecifiedObject.setForeground((QColor::red)) ;
if (rx2.indexIn(value) != -1)
someUnspecifiedObject.setForeground((QColor::orang e));

Both regular expressions match the string, "+", and both colours are applied in order.

aaditya190
5th December 2013, 07:35
It worked.. Thank You very much....