From: Jeff Grice Date: 2007-01-26T23:31:42+09:00 Subject: Re: simple question about Ruby Regext ------=_Part_30972_30663617.1169821900005 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline try "banana".gsub(/an/, "ze") => "bzezea" On 1/26/07, Peter Bailey wrote: > > Alex Young wrote: > > Peter Bailey wrote: > >> > >> This is driving me nuts. Why isn't the RUBY response "=>2?" There are > >> two "an" stubs in "banana." > > The number returned is the position of the start of match, not the > > number of them. > > > >> I thought that RUBY, like PERL, is inherently greedy and it would find > >> all instances of said regex expression. > > It is... there's only one match, and it matches everything from the > > first 'a' to the end of the string. > > > > Hope this makes sense, > > Thanks, Gentlemen. I'll watch my spelling of Ruby and Perl from now on. > > I understand now that my match is only looking for the position. Cool. > Thanks. But, . . ., here's a similar regex where I don't want the > position, but I want to change all instances of the stub, and, it's only > changing the first one. > > "banana".sub(/an/, "ze") > => "bzeana" > > What's with that? > > -Peter > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_30972_30663617.1169821900005--