What is Regular Expression for matching Preprocessor directive statements like #include <stdio.h>?
What is Regular Expression for matching Preprocessor directive statements like #include <stdio.h>?
Don't you think one thread about regular expressions is enough ? link to previous thread
I have a feeling that you want us to do your homework.
Please show us what have you tried so far.
i tried these code but they are not working :
functionFormat1.setFontItalic(false);
functionFormat1.setForeground(Qt::green);
rule.pattern = QRegExp("\\b#([A-Za-z0-9]+ <>)");
rule.format = functionFormat1;
highlightingRules.append(rule);
functionFormat1.setFontItalic(false);
functionFormat1.setForeground(Qt::green);
rule.pattern = QRegExp("\\b[#]([A-Za-z0-9])");
rule.format = functionFormat1;
highlightingRules.append(rule);
Last edited by parulkalra; 26th November 2013 at 05:25.
Read the expressions out in plain English (or your fave language) and I think it is obvious why they will not work (for some definition of work):
The first expression reads:
- A word boundary (matched)
- Followed by # (matched)
- Followed by one or more letters from the set [A-Za-z0-9] (matches "include")
- Followed by a single space (matched)
- Followed by a less than symbol (matched)
- Followed by a greater than symbol (NOT MATCHED)
The second expression reads:
- A word boundary (matched)
- Followed by a single character from the set [#] (matched inefficiently)
- Followed by a single character from the the set [A-Za-z0-9] (matches "i")
This matches the input but not the whole input.
Bookmarks