完整的單詞,而不是子這是我的代碼如何匹配紅寶石
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
我想刪除的話 - 一,一個和所有 但是,相反它匹配子也並刪除它們
舉一個例子輸入 -
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
正如你所看到的,它匹配了子字符串。
如何讓它匹配單詞而不是子字符串?
更改單詞列表,使它們不能位於單詞的中間(例如「an」,「an。」) – 2014-09-19 02:58:29