in reply to Re^4: Checking the include form and getting only the header name
in thread Checking the include form and getting only the header name

The second option I posted (i.e. cutting off the stuff before #include) takes care of that.

Otherwise, if you don't want the comments in the output, simply remove the $ (which means "anchor at end of line") in the first option.

Replies are listed 'Best First'.
Re^6: Checking the include form and getting only the header name
by Anonymous Monk on Mar 20, 2011 at 02:18 UTC

    I noticed the below condition fails for the below input.Basically anything inside " " and <> should match except a space,how can we change the below match for this?

    INPUT:- #include <io-pkt/iopkt_driver.h> --> should match #include "string.h " -->should not match #include "devnp-msm-ipc.h" -->should match if ($line =~ /#include [<"](\w+\.h)[>"]/)

      That's basically what we had in the beginning, except that you probably want \S+ (non-whitespace), or maybe \S.* (if there could be spaces within the file name), in place of \w+:

      if ($line =~ /#include [<"](\S+\.h)[>"]/)

      P.S. "string.h " shouldn't match anyway, because (\w+\.h)[>"] doesn't allow a space between .h and ".

        Thanks Eliya,Does .* match space aswell?Initially I dont care if there is space or anything,I want to match everything(including space) but the following code seems to be not matching for the below given input,how do I change to match everything including space>

        INPUT:- #include "comdef.h " #include <string.h > if ($line =~ /(#include.*\.h[>"])/ ) {