From: "Wolfgang Nádasi-Donner" Date: 2007-01-26T23:35:05+09:00 Subject: Re: simple question about Ruby Regext Peter Bailey schrieb: > Why is this true? > > "banana" =~ /an*/ > =>1 As already said, it is the position of the match. > I thought that RUBY, like PERL, is inherently greedy and it would find > all instances of said regex expression. If you want to find all matches, you should use "scan" in Ruby. There are two possibilities. the first one... str = 'banana' str.scan(/an/) # => ["an", "an"] ...will produce an Array object for each match (see "ri String#scan" for details). The second one will invoke a block for each match. str = 'banana' str.scan(/an/) do puts "#$`<#$&>#$'" end produces: bana bana Wolfgang Nádasi-Donner