Python Regex | Program to accept string ending with alphanumeric character Last Updated : 10 Jun, 2021 Comments Improve Suggest changes Like Article Like Report Prerequisite: Regular expression in PythonGiven a string, write a Python program to check whether the given string is ending with only alphanumeric character or Not.Examples: Input: ankitrai326 Output: Accept Input: ankirai@ Output: Discard In this program, we are using search() method of re module. re.search() : This method either returns None (if the pattern doesn’t match), or re.MatchObject that contains information about the matching part of the string. This method stops after the first match, so this is best suited for testing a regular expression more than extracting data. Alphanumeric characters in the POSIX/C locale consist of either 36 case-insensitive symbols (A-Z and 0-9) or 62 case-sensitive characters (A-Z, a-z and 0-9).Let’s see the Python program for this : Python3 # Python program to accept string ending # with only alphanumeric character. # import re module # re module provides support # for regular expressions import re # Make a regular expression to accept string # ending with alphanumeric character regex = '[a-zA-z0-9]$' # Define a function for accepting string # ending with alphanumeric character def check(string): # pass the regular expression # and the string in search() method if(re.search(regex, string)): print("Accept") else: print("Discard") # Driver Code if __name__ == '__main__' : # Enter the string string = "ankirai@" # calling run function check(string) string = "ankitrai326" check(string) string = "ankit." check(string) string = "geeksforgeeks" check(string) Output : Discard Accept Discard Accept Comment More infoAdvertise with us Next Article Python Regex | Program to accept string ending with alphanumeric character A ankthon Follow Improve Article Tags : Python Python Programs python-regex Python Regex-programs Practice Tags : python Similar Reads Python program to Extract string till first Non-Alphanumeric character Given a string, extract all the alphanumerics before 1st occurrence of non-alphanumeric. Input : test_str = 'geek$s4g!!!eeks' Output : geek Explanation : Stopped at $ occurrence. Input : test_str = 'ge)eks4g!!!eeks' Output : ge Explanation : Stopped at ) occurrence. Method #1 : Using regex + search( 4 min read Python Regex - Program to accept string starting with vowel Prerequisite: Regular expression in PythonGiven a string, write a Python program to check whether the given string is starting with Vowel or Not.Examples: Input: animal Output: Accepted Input: zebra Output: Not Accepted In this program, we are using search() method of re module.re.search() : This me 4 min read Python Program to Find ASCII Value of a Character Given a character, we need to find the ASCII value of that character using Python. ASCII (American Standard Code for Information Interchange) is a character encoding standard that employs numeric codes to denote text characters. Every character has its own ASCII value assigned from 0-127. Examples: 2 min read Python Program for Remove leading zeros from a Number given as a string Given numeric string str, the task is to remove all the leading zeros from a given string. If the string contains only zeros, then print a single "0".Examples:Input: str = "0001234" Output: 1234 Explanation: Removal of leading substring "000" modifies the string to "1234". Hence, the final answer is 3 min read Python program to extract numeric suffix from string Given a string of characters with digits embedded in it. The task is to write a Python program to extract all the numbers that are trailing, i.e at the suffix of the string. Examples:Input : test_str = "GFG04"Output : 04Explanation : 04 is suffix of string and number hence extracted.Input : test_str 7 min read Like