Разделить строку на несколько разделителей Я хочу разделить строку пробелами, , и ' с помощью одной команды ruby. word.split будет разделяться пробелами; word.split(",") будет разбиваться на ,; word.split("\'") будет разбиваться на '. Как сделать все три одновременно? Ответ 1 word = "Now is the,time for'all good people" word.split(/[\s,']/) => ["Now", "is", "the", "time", "for", "all", "good", "people"] Ответ 2 Regex. "a,b'c d".split /\s|'|,/ # => ["a", "b", "c", "d"] Ответ 3 Вот еще один: word = "Now is the,time for'all good people" word.scan(/\w+/) # => ["Now", "is", "the", "time", "for", "all", "good", "people"] Ответ 4 x = "one,two, three four" new_array = x.gsub(/,|'/, " ").split
Ответ 1 word = "Now is the,time for'all good people" word.split(/[\s,']/) => ["Now", "is", "the", "time", "for", "all", "good", "people"]
Ответ 3 Вот еще один: word = "Now is the,time for'all good people" word.scan(/\w+/) # => ["Now", "is", "the", "time", "for", "all", "good", "people"]