From: Andrea Dallera Date: 2010-04-14T01:55:48+09:00 Subject: Re: How to find multiple matches in a string Hei, s = 'abcde_abcde_abcde' m = s.scan(/b/) p m # ['b','b','b'] HTH -- Andrea Dallera http://github.com/bolthar/freightrain http://usingimho.wordpress.com On Wed, 2010-04-14 at 01:51 +0900, Alex DeCaria wrote: > I know how to use regular expressions to find the first match of a > pattern in a string. But, how do I most easily find multiple matches? > For example, if the string is > > s = 'abcde_abcde_abcde' > > and I want to find the location of ALL the 'b' characters, how do I do > it? If I use > > m = s.match(/b/) > > then m.offset(0) => [1,2] > > but I don't have any information about the second or third occurences of > 'b'. > > --Alex