Program to check if a string contains any special character
Given a string, the task is to check if that string contains any special character (defined special character set). If any special character found, don’t accept that string.
Input : Geeks$For$Geeks Output : String is not accepted. Input : Geeks For Geeks Output : String is accepted
Approach : Make a regular expression(regex) object of all the special characters that we don’t want, then pass a string in search method. If any one character of string is matching with regex object then search method returns a match object otherwise return None.
Below is the implementation :
String is not accepted.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course