Table of Contents
Introduction
The task is to check whether the given string starts with vowel using regex expression.
Program
import re def check_str(ip_str): # Regular expression for vowel re_exp = '^[aeiouAEIOU][A-Za-z0-9_]*' if(re.search(re_exp, ip_str)): print("The string starts with vowel!") else: print("The string does not start with vowel!") ip_str = input("Enter the string: ") check_str(ip_str)
Output
Explanation
In the above python code we have created a regex expression of string starting with vowel and passed the expression and sing in search() method. If the pattern is found, the output “The string starts with vowel!” is printed else “The string does not starts with vowel!” is printed.
0 Comments