From: Fleck Jean-Julien Date: 2010-01-04T17:16:33+09:00 Subject: Re: how to capture all conditions using regex > irb(main):001:0> x="123 456 789" > => "123 456 789" > > irb(main):003:0> if /\d{3}/ =~ x > irb(main):004:1>   puts $& > irb(main):005:1> end > 123 > > > For the statement above, I want to capture all "123" and "456" and > "789", not the only "123". > How to do it (must use regex)? Thanks. Try to use the block version of gsub: >> x.gsub(/\d{3}/) {|m| puts m} 123 456 789 Cheers, -- JJ Fleck PCSI1 Lycée Kléber