Program to find sequence of one upper case letter followed by lower case letters

by | Dec 26, 2020 | Python Programs

Home » Python » Python Programs » Program to find sequence of one upper case letter followed by lower case letters

Introduction

The task is to find the sequence of one upper case letter followed by lower case letters using regex expression and print ‘Yes’ if it found else print ‘No’.

find sequence of one upper case letter

Program

import re 
def search(ip_str): 
    re_exp = '[A-Z]+[a-z]+$'
    if re.search(re_exp, ip_str): 
        print('Yes, the required sequence exists!')
    else: 
         print('No, the required sequence does not exists!')
ip_str = input("Enter the string: ")
search(ip_str)

Output

find sequence of one upper case letter Output

Explanation

In the above python code, we have searched the pattern ‘[A-Z]+[a-z]+$’ in the given input. If the pattern is found we print ‘Yes, the required sequence exists!’ otherwise print ‘No, the required sequence does not exist!’.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author