Python regex to find sequences of one upper case letter followed by lower case letters
Write a Python Program to find sequences of one upper case letter followed by lower case letters. If found, print ‘Yes’, otherwise ‘No’.
Examples:
Input : Geeks Output : Yes Input : geeksforgeeks Output : No
Approach: Using re.search()
To check if the sequence of one upper case letter followed by lower case letters we use regular expression ‘[A-Z]+[a-z]+$‘.
# Python3 code to find sequences of one upper # case letter followed by lower case letters import re # Function to match the string def match(text): # regex pattern = '[A-Z]+[a-z]+$' # searching pattern if re.search(pattern, text): return('Yes') else: return('No') # Driver Function print(match("Geeks")) print(match("geeksforGeeks")) print(match("geeks")) |
chevron_right
filter_none
Output:
Yes Yes No
Recommended Posts:
- Python program to count upper and lower case characters without using inbuilt functions
- Python program to convert camel case string to snake case
- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- Regex in Python to put spaces between words starting with capital letters
- Python | Pandas Series.str.lower(), upper() and title()
- isupper(), islower(), lower(), upper() in Python and their applications
- Switch Case in Python (Replacement)
- Python | Toggle characters in words having same case
- Python | Convert case of elements in a list of strings
- Python | Ways to sort list of strings in case-insensitive manner
- Python 3 | Program to print double sided stair-case pattern
- Find all the patterns of “1(0+)1” in a given string using Python Regex
- Python | Find the list elements starting with specific letter
- Python | Find longest consecutive letter and digit substring
- Python | First N letters string construction
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



