Match Any One Lowercase Vowel in Python Using Regular Expression



In this article, you will learn how to match any single lowercase vowel (a, e, i, o, u) using Python regular expressions (regex). We will understand how to use Python's re module to apply a pattern that finds these vowels in a string.

Ways to Match Lowercase

There are two ways to match any one lowercase vowel in Python using a Regular Expression. One is using the if loop, and the other is using a regular expression.

Using the General Method

In the following code, we have matched all the lowercase vowels from the string 'TutRoIals POinT Is A GreAt PlaTfOrm to lEarN '. Here, we did not use a regular expression to match. We used an if loop to match the lowercase vowels.

Example

The following example is a program that shows the matching of any one lowercase vowel in Python using the general method.

string='TutRoIals POinT Is A GreAt PlaTfOrm to lEarN'
lst = []
for i in string:
   if (i=='a' or i=='e' or i=='i' or i=='o' or i=='u'):
      lst.append(i)
print(lst)

On executing the above program, the list of lowercase vowels is printed as output ?

['u', 'o', 'a', 'i', 'e', 'a', 'o', 'a']

Using Regular Expressions

A regular expression is a group of characters that allows you to use a search pattern to find a string or a set of strings. RegEx is another name for regular expressions. The re module in Python is used to work with regular expressions.

Here, we need to match lowercase vowels in Python using a regular expression. To do this, we will use r'[a,e,i,o,u]' regular expression. So here we have used a set of lowercase vowels [a,e,i,o,u] as we need to match them.

Example: Match vowels in a sentence

In the following code, let us see how to match lowercase vowels using a regular expression. We begin by importing the regular expression module. Then, we have used the findall() function. The re.findall() function will return a list containing all matches.

import re
string = 'Tutroials Point is great'
res = re.findall(r'[a,e,i,o,u]', string)
print(res)

On executing the above program, the list of lowercase vowels is printed as output -

['u', 'o', 'i', 'a', 'o', 'i', 'i', 'e', 'a']

Example: Count total vowels

Here we will be going to count the number of vowels present in the given text. The re.findall() function is used to return a list containing all matches. And len() will count all the vowels to show in the output.

import re

text = "beautiful"
vowels = re.findall(r'[aeiou]', text)
print("Total vowels:", len(vowels))

After running the above program, the vowel count is printed as output -

Total vowels: 5

Example: Check if any vowel is present

Here we will be checking if there are any vowels present in the given text -

import re

text = "sky"
if re.search(r'[aeiou]', text):
    print("Vowel found!")
else:
    print("No vowel found.")

When you run the above program, the output will be as follows -

No vowel found.
Updated on: 2025-04-24T11:35:43+05:30

837 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements