文字列を空白で分割し、単一の ruby コマンドを使用し,
たい。'
word.split
空白で分割されます。word.split(",")
で分割され,
ます。word.split("\'")
によって分割され'
ます。
3つすべてを一度に行う方法は?
word = "Now is the,time for'all good people"
word.split(/[\s,']/)
=> ["Now", "is", "the", "time", "for", "all", "good", "people"]
正規表現。
"a,b'c d".split /\s|'|,/
# => ["a", "b", "c", "d"]
ここに別のものがあります:
word = "Now is the,time for'all good people"
word.scan(/\w+/)
# => ["Now", "is", "the", "time", "for", "all", "good", "people"]
x = "one,two, three four"
new_array = x.gsub(/,|'/, " ").split