From: Robert Klemme Date: 2008-08-08T22:15:54+09:00 Subject: Re: Regex. How to return multiple lines 2008/8/8 Damjan Rems : > >> There are of course other possible approaches and depending on what >> you want to do they might be more efficient. >> > > I would baisicly like to have somekind of fulltext search. > > Your example finds 4 letter word in 7.5MB file containing 65000 lines in > 0.13 seconds on C2DUO 2.4 Ghz and 0.35 seconds on PIII 1.3Ghz which is > quite good. If you just want to find all lines with certain words and print them I'd prefer the streamed approach since it works for arbitrary large files as it does not require the whole file to be in memory: File.foreach "x.dat" do |line| puts line if /a+/ =~ line end Of course, using grep or egrep would be even faster. Kind regards robert -- use.inject do |as, often| as.you_can - without end