我正在尝试搜索最多 3 个连续元音
我试过了
grep -E "([AEIOUaeiou]{3})" gpl3.txt
并得到结果
我想要的是不要得到您在输出的第一行中看到的 (aaaaaaaaa)。所有其他输出都是正确的。
感谢任何帮助
最佳答案
如果您想避免使用 -P
选项和前瞻,您可以使用如下所示的内容。
grep -iE '(^|[^aeiou])[aeiou]{3}([^aeiou]|$)' gpl3.txt
刚好匹配
- 行首或非元音
- 三个元音
- 非元音或行尾
测试运行:
IT070137 ~/tmp $ cat gpl3.txt
aaaaaaaaaaaaaaa
asdaiosd
aa
aaa
aaaa
this is a righteous queue
IT070137 ~/tmp $ grep -E '(^|[^aeiou])[aeiou]{3}([^aeiou]|$)' gpl3.txt
asdaiosd
aaa
this is a righteous queue
关于regex - bash 正则表达式 : Search for a maximum of 3 consecutive vowels,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51363540/