I need a RegEx that matches a string containing a letter, numbers, some special characters and spaces. However, RegEx should reject a string consisting of only spaces. I created a template, but it does not work.
import re
pattern = r"^[/<>'\.\,\-\?\[\] \w\d]+$"
print bool(re.match(pattern, "Hi, how are you?"))
print bool(re.match(pattern, "Hi, how are you? &*() "))
print bool(re.match(pattern, " "))
this is the result of the previous snippet:
True
False
True
I need the third test to fail, like the second. I know I can do this using more than just a regular expression, but I would like to know if only a regular expression can be used. Thanks
lCapp source
share