这是我的代码。
我希望删除a、an和all这些词,但实际上它也会匹配字串并将其删除。
例如输入:
我得到的输出是 -
stopwordlist = "a|an|all"
File.open('0_9.txt').each do |line|
line.downcase!
line.gsub!( /\b#{stopwordlist}\b/,'')
File.open('0_9_2.txt', 'w') { |f| f.write(line) }
end
我希望删除a、an和all这些词,但实际上它也会匹配字串并将其删除。
例如输入:
Bromwell High is a cartoon comedy. It ran at the same time as some other programs about school life
我得到的输出是 -
bromwell high is cartoon comedy. it r t the same time s some other programs bout school life
如您所见,它匹配了子字符串。
我该如何使其仅匹配单词而不是子字符串?