Program to check if the string starts with vowel or not using Regex

by | Dec 26, 2020 | Python Programs

Home » Python » Python Programs » Program to check if the string starts with vowel or not using Regex

Introduction

The task is to check whether the given string starts with vowel using regex expression.

check if the string starts with vowel

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

check if the string starts with vowel 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.

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