From: Krishna Dole Date: 2003-04-24T08:00:55+09:00 Subject: grep and regular expressions in ruby 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? 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