From: Robert Klemme Date: 2007-01-26T23:30:11+09:00 Subject: Re: simple question about Ruby Regext On 26.01.2007 15:24, 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? ri String#sub ri String#gsub And, for completeness reasons ri String#sub! ri String#gsub! Kind regards robert