Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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

  • Last Updated : 29 Dec, 2020

Write a Python Program to find sequences of one upper case letter followed by lower case letters. If found, print ‘Yes’, otherwise ‘No’.

Examples:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

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
Recommended Articles
Page :