I need to match members of an array that end with "bar"
but do not start with "foo"
, and put the result in a new array.
Looking at the docs for 1.9.3 and 2.0.0, they seem to support negative look-ahead with the same syntax. Negative look-ahead works as I expect in ruby 2.0.0 but doesn't seem to work in ruby 1.9.3:
["foo a.bar", "b.bar"].grep(/(?!^foo\s).*\.bar$/)
# => ["b.bar"] (ruby 2.0.0)
# => ["foo a.bar", "b.bar"] (ruby 1.9.3)
The ruby version on this infrastructure will be upgraded in 4 months, but changing the version sooner isn't an option. How can I make this work in 1.9.3 and preferably continue to work in 2.0?