Grep-ing an array

Hi,

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

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
returned
if x.grep(y) == /Stalin/
=> [“Joe Stalin”]

so, I have got another array

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

this is the code

$table_array.each{|x|
  reg_text.each{|y|
    real_text.each{|z|
      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?

Cheers

aidy

Quoting aidy [email protected]:

What about Array.assoc(“mystring”)?

how’s that?!

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

puts a.select {|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