From: Logan Capaldo Date: 2005-11-21T08:06:23+09:00 Subject: Re: Building an array of matching strings. ------=_Part_17708_11356772.1132527976582 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 11/20/05, Lloyd Zusman wrote: > > I want to search through a block of text and build an array of all > strings contained within this text that match a given pattern. I know > the following hack will work, but it seems like a misuse of the gsub > method: > > # Assume that 'text' contains the block of text and that 'pat' > # is a Regexp instance containing the pattern to match. > > matchingStrings =3D [] > text.gsub(pat) { > |m| > matchingStrings << m > } > > Is there a cleaner and elegant way to do this? > > Thanks in advance. > > > -- > Lloyd Zusman > ljz@asfast.com > God bless you. I think what you want is matchingStrings =3D text.scan(pat) ------=_Part_17708_11356772.1132527976582--