Program to accept strings ending with alpha numeric characters

by | Dec 26, 2020 | Python Programs

Home » Python » Python Programs » Program to accept strings ending with alpha numeric characters

Introduction

The task is to check whether the string ends with alphanumeric charters or not.

accept strings ending with alpha numeric characters

Program

import re 
def check(ip_str):  
    re_exp = '[a-zA-z0-9]$'
    if(re.search(re_exp, ip_str)):  
        return "The string is ending with alphanumeric char!"  
          
    else:  
        return "The string does not ends with alphanumeric char!"      
      
ip_str = input("Enter the string: ")
print(check(ip_str))

 

Output

accept strings Output

Explanation

In the above python code, the regular expression we have used is ‘[a-zA-Z0-9]$’. The symbol $ signifies the end with character. We have implied the expression on our input and checked whether it satisfies it or not and printed the output accordingly.

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