Can I have Ruby Array element with regex in it?


#1

I want to have an array with case insensitive strings. For example I am planning to assign an array -> arr = ["yes", "Yes", "YEs", "YES"]. In the example since it’s 3-letter word it was easier but how can I do it for a long string?
I tried arr = [ /^(yes)$/i] but I don’t know how to get the array of elements from this.

Any direction on this is really appreciated. Thank you.


#2

#grep method, it can help you.
arr = [“yes”, “no”, “Yes”, “No”, “YEs”, “YES”, “NO”]
puts arr.grep( /^(yes)$/i )