Issue #11049 has been updated by Recursive Madman.


How about implementing `Regexp#invert` instead?

```ruby
  /b/.invert #=> /[^(?:b)]/
```

Like this for example:

```ruby
class Regexp
  def invert
    self.class.new("[^(?:#{source})]")
  end
end

%w(aaa bbb ccc).grep(/b/) #=> ["bbb"]
%w(aaa bbb ccc).grep(/b/.invert) #=> ["aaa", "ccc"]

```



----------------------------------------
Feature #11049: Enumerable#grep_v (inversed grep)
https://bugs.ruby-lang.org/issues/11049#change-52074

* Author: Shota Fukumori
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
sometime I want to do `grep -v` like operation:

    %w(aaa bbb ccc).reject { |x| /b/ === x } #=> ["aaa", "ccc"]

We already have Enumerable#grep, so I propose to add Enumerable#grep_v.

    %w(aaa bbb ccc).grep(/b/) #=> ["bbb"]
    %w(aaa bbb ccc).grep_v(/b/) #=> ["aaa", "ccc"]

## Naming / Interface

This idea is mentioned at DevelopersMeeting20150408Japan by me. Matz has said "I don't disagree for the feature. So this remains naming (interface) problem."

I'm not sure grep_v is the best name for this feature; feedback are welcomed.

### Ideas

- `grep_v(pattern)` (the first patch)
- `grep(pattern, inverse: true)`
- `grep!(pattern)`

---Files--------------------------------
grepv.patch (4.24 KB)


-- 
https://bugs.ruby-lang.org/