简体   繁体   中英

grep consonants in regular expression

I want to use grep to find words that have a specific number of consonants. But using the following command will give me consecutive consonants, How do i modify the command so that non-consecutive consonants are also OK?

grep -iE '[^aeiouy]{3}' filename

Something like this should work

grep -iE '\b[bcdfghjklmnpqrstvwxz][aeiouy]*?[bcdfghjklmnpqrstvwxz][aeiouy]*?[aeiouy][bcdfghjklmnpqrstvwxz]\b'

That will match [a consonant][any number of vowels][consonant][vowel(s)][consonant]

grep -iP '^(?=(.*[^aeiouy]){3}).*$' filename

您可以尝试一下。这将选择在字符串中任何位置至少包含3辅音的单词。使用Pperl模式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM