Grep-ing an array


I am trying to find whether specific strings are contained within a

table_array contains these elements [["", “95424”, “Joe Stalin”, “Field
Sales”, “80%”, “27/06/06”, “”, “Amend”]]

I am grep-ing whether the text I am looking for is in. So I have got an
array of regex

reg_text = /Stalin/, /Field Sales/, /80%/

Now, if the grep finds the string pattern a full string will be
if x.grep(y) == /Stalin/
=> [“Joe Stalin”]

so, I have got another array

real_text = [“Joe Stalin”], [“Field Sales”], [“80%”]

this is the code

      if x.grep(y) == z then p "#{z} is in table" end

But I think it is messy, and I wonder if there was a better way?



Quoting aidy [email protected]:

What about Array.assoc(“mystring”)?

how’s that?!

a = ["", “95424”, “Joe Stalin”, “Field Sales”, “80%”, “27/06/06”, “”,

puts {|i| i =~ /(Stalin|Field Sales|80%)/ }

Pau Garcia i Quiles schrieb:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs