Write a program to check if a string contains any special character


Topic: Write a program to check if a string contains any special character

Solution

  
import re 
def run(string): 
  
    regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]') 
      
    if(regex.search(string) == None): 
        print("String is accepted") 
          
    else: 
        print("String is not accepted.") 
      
  
if __name__ == '__main__' : 
      
    # Enter the string 
    string = "Hello@World"
      
    # calling run function  
    run(string) 
    



List all Python Programs