ar.select {|e| e =~ /cat|small/ }


   ar.select {|e| e =~ /cat/ or e != /small/ }

rubyway?


Krishna Dole wrote:

>I'm quite taken with ruby, but recently I ran into trouble using grep. I
>have two questions: first, is there a way to call grep with multiple
>regexps? For example, if you had
>	ar = ["cat", "dog", "smallcat"]
>
>and you only wanted strings matching  both "small" and "cat", in perl I
>think you could do something like
>	ar2 = grep(( /cat/ and /small/ ), ar );
>
>but in ruby it seems like you have to call grep twice
>	ar2 = ar.grep(/cat/).grep(/small/)
>

   ar.select {|e| e =~ /cat|small/ }


>
>is there a more elegant solution?
>
>The second question concerns regexps: how do you indicate that you don't
>want to match the specified pattern? For example, if I only wanted strings
>containing "cat" but not containing "small". Once again, I think the perl
>would look like this:
>	ar2 = grep(( /cat/ and !/small/ ), ar );
>  
>


>but '!' doesn't work for me in ruby. So far I haven't found anything about
>this in Pickaxe or on the web.
>
>thanks,
>Krishna
>
>
>  
>

-- 
--------------------------------------------------------
Rodrigo Bermejo              | rodrigo.bermejo / ps.ge.com  
IT-Specialist                | 8*879-0644             
--------------------------------------------------------