question archive Write Python program to check that a string contains only a-z, A-Z and 0-9 characters, return True when it is valid
Subject:Computer SciencePrice:3.86 Bought7
Write Python program to check that a string contains only a-z, A-Z and 0-9 characters, return True when it is valid.
Think carefully about when you want to return True or False based on your regular expression.
Use the code skeleton below. Populate '_______________' with an appropriate regular expression. (You can reverse the True and False as would be proper for your regex.):
import re
def is_allowed_specific_char(string):
if re.search( '_______________',string):
return True
else:
return False
print(is_allowed_specific_char("ABCDEFabcdef123450"))
print(is_allowed_specific_char("*&%@#!}{"))
print(is_allowed_specific_char("hello!"))
import re
def is_allowed_specific_char(string):
if re.search( r'[^A-Za-z0-9.]',string):
return False
else:
return True
print(is_allowed_specific_char("ABCDEFabcdef123450"))
print(is_allowed_specific_char("*&%@#!}{"))
print(is_allowed_specific_char("hello!"))
Please see the attached file for the complete solution