Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在搜索一个正则表达式代码,它列出了所有包含 a OR an i 的行。我试过这个:
grep -E '[(a|i)]{1}' testFile.txt
但这给了我包含 a 或 i 的单词和包含 a en i 的单词。怎么了?
您可以通过以下方式实现:
grep -E "^[^ai]*(a|i){1}[^ai]*$" testFile.txt
如果您想要独占 OR,请尝试以下操作: grep -E '^[^i]*a[^i]*$|^[^a]*i[^a]*$'
grep -E '^[^i]*a[^i]*$|^[^a]*i[^a]*$'