Table of Contents
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’.
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
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!’.
0 Comments