From: Rob Biedenharn Date: 2009-09-03T01:30:48+09:00 Subject: Re: regex issue confusing On Sep 2, 2009, at 10:50 AM, Brian Candler wrote: > You may find \b useful: it means "match a word boundary" without > actually consuming any characters. Your example starts with \s (match > one space), so it wouldn't match #include right at the beginning of > the > file. > > But if I remember my C right, the #include has to be at the start of a > line anyway. So perhaps you want: > >>> line = "#include " > => "#include " >>> line[/^\s*#include\s*["<]([^">]+)/, 1] > => "stdio.h" > > HTH, > > Brian. > -- And if you are trying to examine/process C code (and headers), the # must be at the start of the line, but the preprocessor keyword can be separated from the # by optional white space. For example: #ifndef MAXCHAR /* bytes to try to read in at once */ # ifdef i386 # define MAXCHAR 65536 /* might be too big for some systems/devices */ # else # define MAXCHAR 32768 # endif #endif -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com