From: "Shot (Piotr Szotkowski)" Date: 2009-08-29T00:36:20+09:00 Subject: Re: I need a string#all_indices method--is there such a thing? --E39vaYmALEf/7YXx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable timr: > But what if I want to get all the indices for a regex > in the string? Is there an string#all_indices method? How about the below? class String def all_indices needle all =3D [] offset =3D 0 loop do i =3D index needle, offset break if i.nil? all << i offset =3D i + 1 end all end end =E2=80=94 Shot --=20 It may look like I=E2=80=99m just sitting here doing nothing. But I=E2=80=99m really actively waiting for all my problems to go away. --E39vaYmALEf/7YXx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkqX+QQACgkQi/mCfdEo8UobYQCgprrfSXwmYFZaLIlsRuQ/N3T6 JYgAninnzKDr8LA62MzrWmn87vCs3Um8 =+Xms -----END PGP SIGNATURE----- --E39vaYmALEf/7YXx--