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.
- Python - Test if String contains any Uppercase character
- Python program to Count Uppercase, Lowercase, special character and numeric values using Regex
- Python - Check if string contains any number
- Python program to check if a string contains all unique characters
- Python program to read character by character from a file
- Python | Check if string ends with any string in given list
- Python program to check if the list contains three consecutive common numbers in Python
- Python | Check whether string contains only numbers or not
- Python | Ways to check if given string contains only letter
- Python program to verify that a string only contains letters, numbers, underscores and dashes
- Python | Remove tuple from list of tuples if not containing any character
- Python - Remove strings with any non-required character
- Python | Insert character after every character pair
- PyQt5 - Selecting any one check box among group of check boxes
- Python | Check if suffix matches with any string in given list
- Python | Check if any String is empty in list
- Python - Check if string starts with any element in list
- Python - Check whether a string starts and ends with the same character or not (using Regular Expression)
- Python | Check order of character in string using OrderedDict( )
- Python Program to Convert any Positive Real Number to Binary string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.