Search for sub string in an array?

Below is the code

irb(main):0051:0> mistaken_names = [“nmae”,“naem”,“naam”,“nam”]
=> [“nmae”, “naem”, “naam”, “nam”]
irb(main):002:0> substr = “My naem is …”
=> “My naem is …”
irb(main):003:0> qwe = substr
=> “My naem is …”

Now we could just do this

irb(main):004:0> substr.slice!“My “; substr.slice! " is …”
=> " is …”
irb(main):005:0> substr
=> “naem”

And then
irb(main):008:0> if substr == mistaken_names[1]
irb(main):009:1> qwe.gsub!(substr,“name”)
irb(main):010:1> end
=> “name”
irb(main):011:0>

But is there an alternative for doing the same stuff without slicing
strings or even converting every array element into string? Because in
my case we won’t know if it will be “nmae” or “naam"or"nam” instead of
“naem”.

Looking for something like this
mistaken_names = [“nmae”,“naem”,“naam”,“nam”]
input = gets.chomp.downcase #My naem is example
#The ‘naem’ or so can be any from the array element

do
check if input contains any element from mistaken_names
if true get_wrong_name = “naem”
input.gsub!(get_wrong_name,“name”)
=> “My name is example.”

I really apologize for not being able to express myself in an
appropriate way.

cynic limbu wrote in post #1161423:

But is there an alternative for doing the same stuff without slicing
strings or even converting every array element into string?

Take a look at String.split.

irb(main):001:0> ‘My name is Michael’.split
=> [“My”, “name”, “is”, “Michael”]

This may or may not be what you are looking for, but you have to die one
death or another anyway.

with \b delimiter in regexp, you can specify word delimiter,
so you donot need array slicing :

=======================================
herr={
“name” => [“nmae”,“naem”,“naam”,“nam”],
“obama” => [“oboma”,“abomo”,“bomama”],
“regis” => %w{reglis rigles lirles}
}

def re(l) “(#{l.join(”)|(")})" end

def correction(h,string)
h.each_with_object(string.clone) {|(name,lerror),s|
s.gsub!(/\b(#{re(lerror)})\b/,name)
}
end

p correction(herr,“My naam is reglis, yes Mr bomama”)

=> “My name is regis, yes Mr obama”

You can try working with this:

sentence.split.map{ |w| incorrect_names.include?(w) }

Take a look at String.split.

irb(main):001:0> ‘My name is Michael’.split
=> [“My”, “name”, “is”, “Michael”]

This may or may not be what you are looking for, but you have to die one
death or another anyway.

Well, now the question remains is how will we look for the sub string in
the array elements without doing something like

some_array[1] == summ_array[2]

Thanks though, I will try to split my way out.
:stuck_out_tongue: