fork download
  1. import re
  2. r = re.compile(r'[<>%;$]') # Regex matching the specific characters
  3. chars = set('<>%;$') # Define the set of chars to check for
  4.  
  5. def checkString(s):
  6. if any((c in chars) for c in s): # If we found the characters in the string
  7. return False # It is invalid, return FALSE
  8. else: # Else
  9. return True # It is valid, return TRUE
  10.  
  11. def checkString2(s):
  12. if r.search(s): # If we found the "bad" symbols
  13. return False # Return FALSE
  14. else: # Else
  15. return True # Return TRUE
  16.  
  17. s = 'My bad <string>'
  18. print(checkString(s))
  19. print(checkString2(s))
  20. s = 'My good string'
  21. print(checkString(s))
  22. print(checkString2(s))
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
False
False
True
True