I am trying to test whether a character is a special character or not.
It fails for '-' character when I write the following code:
import re
s = '-'
regex = re.compile('[!@#$%^&*()-+]')
if regex.search(s) == None:
print("Not found")
else:
print("Found")
Output>>Not found
However, if I change the position of the '-' character in the pattern as follows (line 3 of code), it works correctly
import re
s = '-'
regex = re.compile('[!@#$%^&*()+-]')
if regex.search(s) == None:
print("Not found")
else:
print("Found")
Output>>Found
What is causing this difference and how can I make sure that the characters will be detected?