Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I stumbled across the following egrep expression:

egrep '^([^aieou]*[aieou]){5,7}[^aieou]*$' /usr/share/dict/words

on this page: http://matt.might.net/articles/sculpting-text

The expression is supposed to find the words that contain between 5 and 7 vowels.

I understand the first ^ meaning from the beginning of the line and the second ^ to negate any of the aieou followed by any number of characters and one of the aeiou between 5 and 7 times. But I did not get how the first and last expressions: [^aieou] help here?

share|improve this question
up vote 1 down vote accepted

It looks for zero or more consonants ([^aieou]*) followed by 5 to 7 vowels (([aieou]){5,7}) followed by zero or more consonants ([^aieou]*). The entire regular expression is anchored to the beginning of the line (^) and the ending, ($).


$ egrep '^([^aieou]*[aieou]){5,7}[^aieou]*$' \
        /usr/share/dict/words | head -10


So when it matches say this first word, abacinate, the first letter a has 0 consonants to the left, so we match that part.

As additional vowels with either zero or more consonants are found on the left and/or right, we match those situations too. If we find 5 to 7 of them, then we match.

share|improve this answer
Thanks. In addition to the ^ pattern, I was also confused by the vowel a in result. The fact that * means zero or more clarifies it. – Ketan Dec 4 '13 at 21:19
Slightly different interpretation - it looks for the pattern of zero or more consonants followed by a single vowel with the pattern repeating 5 to 7 times. The repeated pattern is anchored to the beginning of the line and to the pattern zero or more consonants followed by end-of-line. – Doug O'Neal Dec 5 '13 at 15:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.