我有此葡萄牙语单词列表https://raw.githubusercontent.com/pythonprobr/palavras/master/palavras.txt。我只想提取不以“ er”或“ ar”结尾的单词。我一直在尝试在此问题Regex not matching words ending with "Impl"的答案中应用这些方法,但无法使其正常工作。我一直在从这个答案https://stackoverflow.com/a/22964675/10824251中使用这样的命令:$ grep -oP '[A-Z][A-Za-z\d]*(\?<! er) [ [A-Z] [A-Za-z \\ d] * (\? <! er)] ' palavra.txt > output.txt
要获得所有不以er
和ar
结尾的行,可以使用
grep -v '[ea]r$' palavras.txt > output.txt
注意:
-v
-反转结果,我们得到所有与正则表达式都不匹配的行[ea]r$
-匹配e
或a
,然后匹配字符串末尾的r