From: Martin DeMello Date: 2007-07-20T20:32:13+09:00 Subject: Re: Is there a replacement for sub? On 7/20/07, Robert Dober wrote: > > I was reading this whole thread and I kind of think to be dreaming, I > must have missed something obvious!!! > Anyway maybe this is was OP wants, well I think it is ;) > > 529/29 > irb > irb(main):001:0> a='a b c d e f' > => "a b c d e f" > irb(main):002:0> a.gsub!(" ","") Nope, he wants a method that only replaces the first n occurrences of the pattern. gsub will not do this - you need to run sub in a loop. (This is where perl's "continue matching where you left off" would have been a nice optimisation) martin