
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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']
- Related Articles
- How to match any one uppercase character in python using Regular Expression?\n\n
- How to match any non-digit character in Python using Regular Expression?\n\n
- How to match a word in python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- How to match a nonwhitespace character in python using Regular Expression?
- How to match a single character in python using Regular Expression?
- How to match parentheses in Python regular expression?
- How to match at the beginning of string in python using Regular Expression?
- How to match digits using Java Regular Expression (RegEx)
- PHP – Match regular expression using mb_ereg_match()
- How to match tab and newline but not space using Python regular expression?
- How to match anything except space and new line using Python regular expression?
- How to match nonword characters in Python using Regular Expression?\n\n\n\n
- How to match non-digits using Java Regular Expression (RegEx)
