- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to match any one lowercase vowel in python using Regular Expression?
There are two ways to match any one lowercase vowel in python using Regular Expression. One is the general method and other is using the 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 regular expression to match. We used the general method to match the lowercase vowels.
Example
The following example is a program which 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)
Output
On executing the above program, the list of lowercase vowels is printed as output.
['u', 'o', 'a', 'i', 'e', 'a', 'o', 'a']
Using Regular Expression
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.
In this article we will match lowercase vowel in python using regular expression. To achieve this, we use r'[a,e,i,o,u]' regular expression. Here, we have used a set of lowercase vowels [a,e,i,o,u] as we need to match them.
Example
In the following code, let us see how to match lowercase vowels using regular expression. We begin by importing regular expression module.
import re
Then, we have used findall() function which is imported from the re module.
import re string = 'Tutroials Point' res = re.findall(r'[a,e,i,o,u]', string) print(res)
The re.findall() function returns a list containing all matches.
Output
On executing the above program, the list of lowercase vowels is printed as output.
['u', 'o', 'i', 'a', 'o', 'i']