我有一个字符串:
"hello\t World\nbla"
我想把它分成:
["hello\t ",
"World\n",
"bla"]
我如何在Ruby中执行此操作?
答案 0 :(得分:8)
>> "hello\t World\nbla".scan /\S+\s*/
=> ["hello\t ", "World\n", "bla"]
答案 1 :(得分:2)
希望这会有所帮助..
>> "hello\t World\nbla".scan(/\w+\s*/)
=> ["hello\t ", "World\n", "bla"]