文字列を複数の区切り文字で分割する
概要
単一の Ruby コマンドを使用して文字列を空白、‘、’ で分割したいと考えています。
3つすべてを一度に行うにはどうすればよいですか?
解決策
word = "Now is the,time for'all good people"
word.split(/[\s,']/)
=> ["Now", "is", "the", "time", "for", "all", "good", "people"]
単一の Ruby コマンドを使用して文字列を空白、‘、’ で分割したいと考えています。
3つすべてを一度に行うにはどうすればよいですか?
word = "Now is the,time for'all good people"
word.split(/[\s,']/)
=> ["Now", "is", "the", "time", "for", "all", "good", "people"]