From: Mike Campbell Date: 2003-04-24T09:02:35+09:00 Subject: Re: grep and regular expressions in ruby > -----Original Message----- > From: Daniel Carrera [mailto:dcarrera@math.umd.edu] > Sent: Wednesday, April 23, 2003 7:28 PM > To: ruby-talk ML > Subject: Re: grep and regular expressions in ruby ... > I don't know if this is the Ruby-way or not, but I do think that Ruby's > RE's and grep are lacking. There should be a way to express negation in > a regular expression, and there should be a way to express several > conditions in grep. I guess that the complaint over grep really reduces > to a complaint over REs. > > IMHO one should be able to type some sort of equivalent to > > "/cat/ and not /small/". > > Just like we have "/cat|small/". > > I have found myself wishing for something like that more than once. > > I can see that the exact syntax I wrote can't be made to work, but we can > probably find an alternate RE-like syntax. Perhaps something like: > > /cat|small/ -> true if matches /cat/ or matches /small/ > /cat&small/ -> true if matches /cat/ and matches /small/ > /cat|!small/ -> true if matches /cat/ or does not match /small/ > /cat&!small/ -> true if matches /cat/ and does not match /small/ > > Just my $0.02 Does the "!~" operator help you out here? "cat" =~ /cat/ => 0 "cat" !~ /cat/ => false