我的代码在这里
str= "In 2004, Obama received national attention during his campaign to represent Illinois in the United States Senate"
arr =str.scan(/\S+(?:\s+\S+)?/)
it gives
arr=["In 2004,", "Obama received", "national attention", "during his", "campaign to", "represent Illinois", "in the", "United States", "Senate"]
fresh_arr=[]
arr.each do |el|
if !arr.match(/is|am|are|this|his/)
fresh_arr << el
end
end
现在我想删除包含 (is,am,are,this,his) 类型字符串的元素,然后得到类似这样的结果
arr=["Obama received", "national attention","represent Illinois","United States", "Senate"]
我有非常大的数据,需要 6 秒我可以用其他方法吗?