Windows 7 SP1
MSVS 2010
Qt 4.8.4
I'm experimenting with the Qt Syntax Highlighter Example.
I have an application that needs to highlight words that start with a hyphen. So I modify the regular expression from this code fragment:
classFormat.setFontWeight(QFont::Bold);
classFormat.setForeground(Qt::darkMagenta);
rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
rule.format = classFormat;
highlightingRules.append(rule);
which highlights words that start with Q. I change it to:
rule.pattern = QRegExp("\\b-[A-Za-z]+\\b");
and nothing happens.
I try
rule.pattern = QRegExp("\\b\\-[A-Za-z]+\\b");
Nothing.
Out of curiosity, I try
rule.pattern = QRegExp("\\b[-A-Za-z]+\\b");
If I start typing a hyphen, the hyphen is unhighlighted and every other alpha is highlighted. According to How to match hyphens with Regular Expression? this should be kosher.
Question: How do I write the regular expression to highlight words starting with a hyphen?