Get array element by using grep : grep « Array « Ruby






Get array element by using grep


a = ["a", "b", "c", "d", "e", "f", "g", "h"]
p a.grep /[aeiou]/                 # => ["a", "e"]

 








Related examples in the same category

1.grep /[^g]/
2.Start with 'p'
3.grep numbers