regex - bash 正则表达式 : Search for a maximum of 3 consecutive vowels

标签 regex linux bash grep

我正在尝试搜索最多 3 个连续元音

我试过了

grep -E "([AEIOUaeiou]{3})" gpl3.txt

并得到结果

enter image description here

我想要的是不要得到您在输出的第一行中看到的 (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/

相关文章:

javascript - 使用 Regex 以多种方式拆分单词

linux - 传递给分离屏幕的多字 Bash 脚本参数

linux - bash 脚本中的菜鸟

正则表达式 - 捕获匹配之间的文本,如果没有匹配,则捕获所有

R - 替换正则表达式匹配的最后一个实例以及之后的所有内容

linux - 如何从脚本运行 grep 并将输出存储在 bash 脚本的目标目录中的文件中

bash - 为什么Bash读取命令没有输入就返回?

linux - 使用伪终端从 sudo 中删除冗长

php - 为什么在使用\b 字边界时使用 = 或 "break PHP regex 等特殊字符?

linux - 在 ssh 进入远程机器时进行 scp?