From: James Edward Gray II Date: 2006-02-22T22:53:51+09:00 Subject: Re: A regexp for an include? method On Feb 22, 2006, at 6:52 AM, Boucher, Eric wrote: > Hi, > > I want to see if a certain pattern is inside an array. I tried: > myArray.flatten.include?(/myPattern/) > > but it always return false. Why? Is it because the "include?" > doesn't takes > regular expressions? > Here's another example that I tried inside an irb session: > > data = ["TC_TP1", "TC_TP2", "TC_TP3"] > =>["TC_TP1", "TC_TP2", "TC_TP3"] > data.include?(/TC_TP/) > => false > data.include?(/TC_TP.*/) > => false > data.include?(/TC_TP1/) > => false > data.include?("TC_TP1") > => true !!! You can use grep() for this: >> data = ["TC_TP1", "TC_TP2", "TC_TP3"] => ["TC_TP1", "TC_TP2", "TC_TP3"] >> data.grep(/TC_TP/) => ["TC_TP1", "TC_TP2", "TC_TP3"] >> !data.grep(/TC_TP/).empty? => true Hope that gives you some fresh ideas. James Edward Gray II