仅提取不包含以特定字母组合结尾的单词的单词(仅使用正则表达式)

extract only words that do not contain words ending with a particular letter combination (using regex only)

我有这个葡萄牙语单词列表 https://raw.githubusercontent.com/pythonprobr/palavras/master/palavras.txt. I want to extract only words that do not end in "er" or "ar". I have been trying to apply the methods in the answers to this question Regex not matching words ending with "Impl",但我无法使用它。 我一直在使用这个答案中的命令 : $ grep -oP '[A-Z][A-Za-z\d]*(\?<! er) [ [A-Z] [A-Za-z \ d] * (\? <! er)] ' palavra.txt > output.txt

要获取所有不以 erar 结尾的行,您可以使用

grep -v '[ea]r$' palavras.txt > output.txt

备注:

  • -v - 反转结果,我们得到所有不匹配正则表达式的行
  • [ea]r$ - 匹配 ea,然后匹配字符串末尾的 r