基于子串匹配创建基于子阵列

kry*_*tah 1 ruby

如果我有一个字符串数组,我怎么能创建一个只包含原始数组中包含子字符串"yellow"的元素的子数组?

Aru*_*hit 5

您可以使用#grep此方法: -

# will give all strings have a sub-string `yellow` as a subarry
array.grep(/yellow/) 
Run Code Online (Sandbox Code Playgroud)