用两个或多个连续的空格而不是单个空格拆分字符串

Split string by two or more consecutive whitespaces but not by single

我有

str = "this     is    simpl e    string 98"

我需要这样的东西

["this","is","simple","string","98"]

我这样做了:

str.split(" ")
# => ["this","is","simpl","e","string","98"]

使用 gsub 函数删除存在于两个字母之间的单个 space,然后按顺序进行拆分以获得所需的输出。

> str = "this     is    simpl e    string 98"
> str.gsub(/(?<=[[:alpha:]])\s(?=[[:alpha:]])/,"").split()
=> ["this", "is", "simple", "string", "98"]