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 lettersimport re # Function to match the stringdef match(text): # regex pattern = '[A-Z]+[a-z]+$' # searching pattern if re.search(pattern, text): return('Yes') else: return('No') # Driver Functionprint(match("Geeks"))print(match("geeksforGeeks"))print(match("geeks")) |
Output:
Yes Yes No





Please Login to comment...