From: Robert Klemme Date: 2010-01-04T22:05:05+09:00 Subject: Re: how to capture all conditions using regex On 01/04/2010 09:33 AM, Ruby Newbee wrote: > Thanks all for the quick response. > In perl there is a "/g" option which can be used for multi-matching. > > # perl -le '$x="123 456 789"; @x=$x=~/\d{3}/g; print "@x"' > 123 456 789 > > I try to find ruby's instead one, but never thought there is already a > scan method available. Note that even with #scan you have two options: you can either take the Array returned or use the block form to do something whenever a match occurs: > irb(main):004:0> s = "123 456 789" > => "123 456 789" > irb(main):005:0> s.scan /\d+/ > => ["123", "456", "789"] > irb(main):006:0> s.scan /\d+/ do |match| p match end > "123" > "456" > "789" > => "123 456 789" Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/