Results 1 to 4 of 4

Thread: Regular Expression to match preprocessor directive statement

  1. #1
    Join Date
    Nov 2013
    Posts
    11
    Qt products
    Qt5

    Default Regular Expression to match preprocessor directive statement

    What is Regular Expression for matching Preprocessor directive statements like #include <stdio.h>?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Regular Expression to match preprocessor directive statement

    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.

  3. #3
    Join Date
    Nov 2013
    Posts
    11
    Qt products
    Qt5

    Default Re: Regular Expression to match preprocessor directive statement

    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.

  4. #4
    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 to match preprocessor directive statement

    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):
    Qt Code:
    1. #include <stdio.h>
    To copy to clipboard, switch view to plain text mode 

    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.

Similar Threads

  1. Replies: 2
    Last Post: 26th November 2013, 05:15
  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

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.