Regex for Matching Vowels [aeiou]

There are 5 vowels in the English language (aeiou). Finding all vowels in a string of text or finding all words that contain vowels can sometimes be useful.

A regular expression that matches all vowels makes use of a character range (square brackets) that contains all the vowels (e.g. [aeiou]). To match double vowels or diphthongs, add a quantifier {2} behind the character range.

An expression that matches all vowels in a string is:

/[aeiou]/Edit with Regexity

The letter yEdit with Regexity sometimes functions as a vowel, and sometimes as a consonant. To match it as well, the expression will change to:

/[aeiouy]/Edit with Regexity

These expressions will match any vowel in a string of text.

ALSO READ: Regex for Alphabetic Characters

How It Works

The expression above is accomplished by including all 5 vowels (6 if you’re counting y) in square brackets []Edit with Regexity. The square brackets indicate a character range, meaning that any character inside the square brackets will be matched.

Matching Double Vowels or Diphthongs

To match double vowels like aeEdit with Regexity or ooEdit with Regexity we need to include a quantifier behind the square brackets to indicate how many vowels we would like to match.

/[aeiou]{2}/Edit with Regexity

The {2}Edit with Regexity behind the square brackets acts as a quantifier to specify how many successive vowels from the square brackets we would like to match. The number can easily be adjusted to the number of vowels you would like to match. For example, if you’d like to match 3 vowels, use {3}Edit with Regexity:

/[aeiou]{3}/Edit with Regexity

Regex for Words Containing Vowels

To match any word that contains a vowel, we can include a character range of all letters [a-z]Edit with Regexity before and after the vowel character set.

/[a-z][aeiou][a-z]/Edit with Regexity

The expression above will only match one other letter before and after each vowel, so we can include a zero-or-more quantifier *Edit with Regexity behind each of the [a-z]Edit with Regexity character ranges to match zero or more letters:

/[a-z]*[aeiou][a-z]*/Edit with Regexity

To include uppercase letter into the mix, we can either add uppercase letter ranges [A-Z]Edit with Regexity into both letter character ranges:

/[A-Za-z]*[aeiou][A-Za-z]*/Edit with Regexity

Or we can add a case insensitive flag iEdit with Regexity behind the entire expression, which will match all words containing vowels regardless of their case.

/[a-z]*[aeiou][a-z]*/iEdit with Regexity

Regex for Words that Do Not Contain Vowels

To match all words that do not contain a vowel, we can start with a letter character range that contains all consonants and excludes the vowels. In the character range, aEdit with Regexity is excluded because it is a vowel. The letters b-dEdit with Regexity are included, eEdit with Regexity is excluded, f-hEdit with Regexity are included, iEdit with Regexity is excluded, and so on…

/[b-df-hj-np-tv-z]/Edit with Regexity

The expression above will only match one of these characters. We can use the one-or-more quantifier +Edit with Regexity behind the square brackets to match one or more of these characters.

/[b-df-hj-np-tv-z]+/Edit with Regexity

To ensure we match entire words instead of only parts of a word, we can insert a word break \bEdit with Regexity before and after the square brackets. This will ensure that the returned match starts and ends at the beginning of a word.

/\b[b-df-hj-np-tv-z]+\b/Edit with Regexity

And finally, to allow both uppercase and lowercase words to be matched, we can include the case insensitive flag iEdit with Regexity behind the entire expression:

/\b[b-df-hj-np-tv-z]+\b/iEdit with Regexity

Regex for Words Containing Only Vowels

To match words containing only vowels, we start with the vowel character class [aeiou]Edit with Regexity and add a one-or-more quantifier +Edit with Regexity after it:

/[aeiou]+/Edit with Regexity

To force a match of entire words instead of only parts of a word, add a word break character \bEdit with Regexity before and after the character range:

/\b[aeiou]+\b/Edit with Regexity

And finally, to ensure that words in all cases are matched, add a case insensitive flag iEdit with Regexity to the end of the entire expression:

/\b[aeiou]+\b/iEdit with Regexity

ALSO READ: Regex for Alphanumeric Strings

Sources

The regular expressions on this page were adapted from solutions presented on Stack Overflow by RobG on this question, by HamZa on this question, and by CertainPerformance on this question.

Benjamin

Founder, owner, and sole content creator on RegexLand. Enjoys programming, blogging, and teaching others how to do the same. Read more...

4 thoughts on “Regex for Matching Vowels [aeiou]”

    • Try something like the following expression:

      /\b[aeiou]{1}[a-z]*[^aeiou\s]{1}\b/

      \b = matches a word boundary
      [aeiou]{1} = character class and quantifier matching exactly one instance of a, e, i, o, or u.
      [a-z]* = character class and quantifier matching zero of more lowercase letters
      [^aeiou]{1} = negated character class and quantifier matching exactly one instance of characters that are not a, e, i, o, u, or whitespace.
      \b = matched a word boundary

      Reply

Leave a Reply to Benjamin Cancel reply