Everyone else's method doesn't account for whitespaces. Obviously nobody really considers a whitespace a special character.
Use this method to detect special characters not including whitespaces:
import re
def detect_special_characer(pass_string):
regex= re.compile('[@_!#$%^&*()<>?/\|}{~:]')
if(regex.search(pass_string) == None):
res = False
else:
res = True
return(res)
You will need to define "special characters", but it's likely that for some string s
you mean:
import re
if re.match(r'^\w+$', s):
# s is good-to-go
Source: Stackoverflow.com