itβs better to use this, which looks more convincing:
matched = array.grep(/^(?!foo\s).*\.bar$/)
NOT starting with foo
this will work in both 2.1.1 and 1.9.3
only if you want to see what I did:
rituraj@rituraj :~$ rvm use ruby-1.9.3-p362 Using /home/rituraj/.rvm/gems/ruby-1.9.3-p362 rituraj@rituraj :~$ irb 1.9.3-p362 :001 > array = ["foo a.bar", "b.bar"] => ["foo a.bar", "b.bar"] 1.9.3-p362 :002 > matched = array.grep(/(?!^foo\s).*\.bar$/) => ["foo a.bar", "b.bar"] 1.9.3-p362 :003 > matched = array.grep(/^(?!foo\s).*\.bar$/) => ["b.bar"] 1.9.3-p362 :004 > matched = array.grep(/(?!^foo\s).*\.bar$/) => ["foo a.bar", "b.bar"] 1.9.3-p362 :005 > ^C 1.9.3-p362 :005 > rituraj@rituraj :~$ rvm list rvm rubies => ruby-1.9.3-p362 [ x86_64 ] * ruby-2.1.1 [ x86_64 ]
source share