30/11/2022
import re
# import required package as above
3 program to check if a string contains any special character
checks if the string contains any special character
def run(string):
own character set and pass this as argument in compile method.
regex = re.compile('! #%&*()?/\|}{~:]')
# Pass the string in search Method of regex object.
if (regex.search(string) == None):
print("String is accepted")
else:
print("String is not accepted")
code
if __name__ == "__main__":
the string
string = "Hello$ #{}World"
run function
run(string)