From: Luis Parravicini Date: 2007-01-24T02:50:44+09:00 Subject: Re: Using Regular Expressions in Arrays On 1/23/07, JT Kimbell wrote: > 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. Array.include? checks if the array contains the object you passed as argument. > Anyway, my question is if I can use regex to find an array element(s)? I'm sure there are better ways of doing it, but as far as I know, I would do it with using something like: x.map { |x| x if x =~ /regexp/ }.compact The array returned are the elements which match the regexp Luis