我正在使用currentState
方法,但在split(/ /)
之后,结束的空白区域消失了。
匹配的字符串是:
join
从split(/ /)返回的数组是:
"word word word "
我期待这个:
["word", " ", "word", " ", " ", "word"]
答案 0 :(得分:2)
这应该对你有用
str.scan(/\w+| /)
这是一个例子
2.2.1:003> "单词单词" .scan(/ \ w + | /)
=> ["字"," "," word"," "," "," word"," "]