From: Robert Klemme Date: 2009-11-29T01:55:06+09:00 Subject: Re: where is grep? On 11/28/2009 05:35 PM, Rick DeNatale wrote: > On Sat, Nov 28, 2009 at 11:10 AM, Robert Klemme > wrote: >> On 11/28/2009 08:27 AM, David A. Black wrote: >>> I would probably do this in 1.9: >>> >>> string.lines.grep(/pattern/) >>> >>> where lines returns an enumerator. >> Why not just string.scan(/pattern/) ? > > Not the same thing > > using 1.9 > > irb(main):001:0> a = "abe\nbob\nfred\njim" > => "abe\nbob\nfred\njim" > irb(main):002:0> a.scan(/b/) > => ["b", "b", "b"] > irb(main):003:0> a.lines.grep(/b/) > => ["abe\n", "bob\n"] > > a.lines.grep does the same thing that a.grep would do in 1.8, a.scan does not. Stupid me, of course! Thanks for the quick enlightenment. I somehow had assumed the text the OP was ultimately interested in was that matched by the expression. But that assumption is not covered by the posting. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/