From: ara.t.howard@... Date: 2007-04-17T23:50:56+09:00 Subject: Re: Regular expression help On Tue, 17 Apr 2007, Guest wrote: > I have a line such as: > > #define BLAH 10 > > or > > #include "BLAH.h" > > and I'm going around in circles trying to just get the 'include' or 'define' > bit...anyone can help me? > > Thanks > Bob. harp:~ > cat a.rb lines = '#define BLAH 10', '#include "BLAH.h"', ' #define BLAH 10', ' # include "BLAH.h"' re = %r/^\s*(#)\s*(\w+)\s*(.*)$/o lines.each do |line| match, pound, directive, rest = re.match(line).to_a p [pound, directive, rest] if match end harp:~ > ruby a.rb ["#", "define", "BLAH 10"] ["#", "include", "\"BLAH.h\""] ["#", "define", "BLAH 10"] ["#", "include", "\"BLAH.h\""] -a -- be kind whenever possible... it is always possible. - the dalai lama