用Ruby计算分词

Pra*_*tha 5 ruby regex ruby-on-rails-3

当我拆分字符串"hello world/n"时

"hello world \n".scan(/\w+/)
Run Code Online (Sandbox Code Playgroud)

我明白了 ["hello", "world"]

我想将\n或\ t计为字符串.

Dut*_*tow 5

你想要这样的东西吗?

"hello world \n".scan(/\w+|\n/)
Run Code Online (Sandbox Code Playgroud)