I want to replace an item in an array:
arr = ["55", "4.ARTHUR", "masddf"]
with potentially multiple items based on whether it matches a regular expression. I would like to have the result:
["55", "4.", "ARTHUR", "masddf"]
I tried:
arr.map { |o| o =~ /\d+\./ ? o.split(/^(\d+\.)/).reject { |c| c.empty? } : o }
# => ["55", ["4.", "ARTHUR"], "masddf"]
arr.map { |o| o =~ /\d+\./ ? o.split(/^(\d+\.)/).reject { |c| c.empty? }.flatten : o }
# => ["55", ["4.", "ARTHUR"], "masddf"]
I can't seem to get the elements outside of the array they got split into. Any ideas?