我刚刚使用了以下正则表达式example.gsub(/[\s+\W|\d+]/, " ")
这个
" Beginning of Year Mid Year End of Year New Year"
我该怎么做才能让它看起来像这样
"Beginning of year", "Mid Year", "End of Year", "New Year"
我尝试使用split方法,这会将所有单词拆分为类似
的数组"Beginning", "of", "New", "Year"
希望你明白这一点。
答案 0 :(得分:2)
" Beginning of Year Mid Year End of Year New Year"
.strip.split(/\s{2,}/)
# => ["Beginning of Year", "Mid Year", "End of Year", "New Year"]