How to do grep -v?

c.grep(/[^a]/)

Regards,

Dan

···

-----Original Message-----
From: Jim Freeze [mailto:jim@freeze.org]
Hi

Is there a more direct way than this to get ‘grep -v’?

c=%w{a b c} #=> [“a”, “b”, “c”]
c -= c.grep(/a/) #=> [“b”, “c”]

I would much rather do:

c.grep!(/a/v)
or
c.grep!(/a/,‘v’)

Or even:

c.delete(‘a’)

Ian

···

On Fri 31 Jan 2003 at 05:22:16 +0900, Berger, Daniel wrote:

-----Original Message-----
From: Jim Freeze [mailto:jim@freeze.org]
Hi

Is there a more direct way than this to get ‘grep -v’?

c=%w{a b c} #=> [“a”, “b”, “c”]
c -= c.grep(/a/) #=> [“b”, “c”]

c.grep(/[^a]/)


Ian Macdonald | Hear about… the cross-eyed shoe
ian@caliban.org | fetishist who was always getting off on the
> wrong foot?
>
>

Doesn’t work for ‘a’ being more than one character.
How does one do a negative regex match?

Jim

···

On Friday, 31 January 2003 at 5:29:27 +0900, Ian Macdonald wrote:

On Fri 31 Jan 2003 at 05:22:16 +0900, Berger, Daniel wrote:

-----Original Message-----
From: Jim Freeze [mailto:jim@freeze.org]
Hi

Is there a more direct way than this to get ‘grep -v’?

c=%w{a b c} #=> [“a”, “b”, “c”]
c -= c.grep(/a/) #=> [“b”, “c”]

c.grep(/[^a]/)


Jim Freeze

Paranoids are people, too; they have their own problems. It’s easy to
criticize, but if everybody hated you, you’d be paranoid too.
– D. J. Hicks

Well, there’s Enumerable#reject – but it takes a
block. Might be nice if there were a regex version
also. But that opens the proverbial can of worms.

Hal

···

----- Original Message -----
From: “Jim Freeze” jim@freeze.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, January 30, 2003 3:49 PM
Subject: Re: How to do grep -v?

c.grep(/[^a]/)

Doesn’t work for ‘a’ being more than one character.
How does one do a negative regex match?

Is there a more direct way than this to get ‘grep -v’?

c=%w{a b c} #=> [“a”, “b”, “c”]
c -= c.grep(/a/) #=> [“b”, “c”]

How about c.reject {|e| e =~ /a/} ?
(or c.delete_if if you want to modify c)

HTH,

Bill

···

From: “Jim Freeze” jim@freeze.org

Hi,

···

At Fri, 31 Jan 2003 06:49:15 +0900, Jim Freeze wrote:

Is there a more direct way than this to get ‘grep -v’?

c=%w{a b c} #=> [“a”, “b”, “c”]
c -= c.grep(/a/) #=> [“b”, “c”]

c.grep(/[^a]/)

Doesn’t work for ‘a’ being more than one character.
How does one do a negative regex match?

Try http://member.nifty.ne.jp/nokada/archive/reop.rb.

require ‘reop’
c.grep(-/a/)


Nobu Nakada

RAA.search ‘reop’ # => nil

Gavin

···

On Friday, January 31, 2003, 9:18:48 AM, nobu wrote:

Hi,

At Fri, 31 Jan 2003 06:49:15 +0900, > Jim Freeze wrote:

Is there a more direct way than this to get ‘grep -v’?

c=%w{a b c} #=> [“a”, “b”, “c”]
c -= c.grep(/a/) #=> [“b”, “c”]

c.grep(/[^a]/)

Doesn’t work for ‘a’ being more than one character.
How does one do a negative regex match?

Try http://member.nifty.ne.jp/nokada/archive/reop.rb.