From: Martin DeMello Date: 2006-12-21T07:17:07+09:00 Subject: Re: Searching Stings with Arrays? On 12/21/06, Phil Cooperking wrote: > > this is what I got > @string = "mozilla/5.0 (macintosh; u; ppc mac os x; en) > applewebkit/418.9.1 (khtml, like gecko) safari/419.3" > > array = ["shiira", "msie", "safari", "firefox", "netscape"] > > so I'd like to search the string for any matches, it should stop at > safari and bob's sombodys uncle. array.find {|b| @string =~ /#{b}/} Iterates over each entry of the array, makes a regexp of it (the /#{b}/ bit) and matches that against the string. (Ideally, you want @string =~ Regexp.escape(b), but with the strings you have it comes to the same thing.) martin