Skip to content
Related Articles
Open in App
Not now

Related Articles

Python regex to find sequences of one upper case letter followed by lower case letters

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 29 Dec, 2020
Improve Article
Save Article

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"))


Output:

Yes
Yes
No
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!