From: matz@... (Yukihiro Matsumoto) Date: 2003-04-24T17:30:28+09:00 Subject: Re: grep and regular expressions in ruby Hi, In message "grep and regular expressions in ruby" on 03/04/24, "Krishna Dole" writes: |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/) | |is there a more elegant solution? ar2 = ar.select{|x| /cat/ =~ x and /small/ =~ x} matz.