
- 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 uppercase character in python using Regular Expression?nn
There are two ways to match any one uppercase character in python using Regular Expression. One is the general method and other is using the regular expression.
Using Regular Expression
A regular expression is a series of characters that allows you to discover a string or a set of strings using a search pattern. Regular expressions are sometimes known as RegEx. In Python, the re module is used to work with regular expressions.
In this article we will match the uppercase 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 uppercase vowels [A,E,I,O,U] as we need to match them. In the following code, lets us see how to match lowercase vowels.
Example
In the following code, let us see how to match uppercase 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 Is A GreAt PlaTfOrm to lEarN' 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 uppercase vowels is printed as output.
['I', 'O', 'I', 'A', 'A', 'O', 'E']
Using General method
In the following code, we have matched all the uppercase vowels from the string 'TutRoIals POinT Is A GreAt PlaTfOrm to lEarN'. Here we did not use regular expression to match.
Example
The following example is a program which shows the matching of any one uppercase character 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 uppercase vowels is printed as output.
['I', 'O', 'I', 'A', 'A', 'O', 'E']
- Related Articles
- How to match any one lowercase vowel in python using Regular Expression?
- How to match any non-digit character in Python using Regular Expression?\n\n
- 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 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 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)
- How to match any character using Java 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
