From: Tim Hunter Date: 2007-01-24T02:50:10+09:00 Subject: Re: Using Regular Expressions in Arrays JT Kimbell wrote: > Hey everyone, > > Right now I have an array of terms and I want to delete/find a term > using pattern matching. > > For example, I have the following array (this is a very simple example). > > x = ["dog", "cat", "moose"] > > x.include?(/dog/) returns false. > > Now, I understand regular expressions, and can usually get one that > works, but perhaps I am using them wrong in ruby? > > Anyway, my question is if I can use regex to find an array element(s)? > > Thanks, > > JT > x.include? tests to see if the regular expression /dog/ is an element of x, not if some element in x matches /dog/. See the difference? Anyway, check out Enumerable#find and Array#delete_if.