Write a python program to read a string with five characters that start with ‘a’ and end with ‘z’
Problem Definition:
Write a program that reads a string with five characters that starts with ‘a’ and ends with ‘z’.
Print search successful if pattern match found.
Video Tutorial
Source Code to Python Program to read five characters which start with ‘a’ and end with ‘z’
# Regular Expression =>^a[a-zA-Z]{3}z$ import re s = input("Enter the string: ") pat = re.compile(r'^a[a-zA-Z]{3}z$') matched = pat.search(s) if matched != None: print ("Search is successful") else: print ("Search is unsuccessful")
Output
Case 1:
Enter the string: aqwez
Search is successful
Case 2:
Enter the string: aqwer
Search is unsuccessful
Summary:
This tutorial discusses how to write a Python Program to read five characters that start with ‘a’ and end with ‘z’. If you like the tutorial share it with your friends. Like the Facebook page for regular updates and the YouTube channel for video tutorials.