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

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)[>"]/)

Replies are listed 'Best First'.
Re^7: Checking the include form and getting only the header name
by Eliya (Vicar) on Mar 20, 2011 at 02:34 UTC

    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[>"])/ ) {

        Never mind.I figured out the above query

        Can anyone advise how can I change the below code for the below given input?

        INPUT:- #include "string.h" -->works for below code #include <stdlib.h> --> words for below #include <sys/dispatch.h> --> doesn't work,should work for all the thr +ee cases if ($line =~ /#include [<"](\S+\.h)[>"]/) { print "$1\n"; }