What is a grep pattern that can search for only the words that alternate vowels and consonents?(including 2 letter combinations)

Viewed 33

I need to make homework and i need to grep all words that alternate vowels and consonants. I know this question has been asked before but the solution given doesn't work for 2 letter combinations like AB.

The command i used almost finds everything and is the only thing that got close, but as mentioned before it doesn't work for everything.

grep -iE "^[aeiou]?([^aeiou][aeiou])+[^aeiou]?$" words.txt

Is there a simple solution to my problem that finds all words alternating vowels and consonants including 2 letter combinations.

1 Answers

Is there a simple solution to my problem that finds all words alternating vowels and consonants including 2 letter combinations.

It seems we have to use the alternation operator |:

grep -iE "^[aeiou]?([^aeiou][aeiou])+$|^[^aeiou]?([aeiou][^aeiou])+$" words.txt
Related