在python中Re.match始终返回None

在python中Re.match始终返回None,python,regex,python-3.x,Python,Regex,Python 3.x,我试图进行一个非常简单的正则表达式匹配(对除“[”和“]”之外的所有可打印anscii字符求反)。我得到了我想要的匹配。然后我转到python单元测试,我的匹配永远不会返回true def testChatChars(string): return re.match('[^\x20-\x5A\x5C\x5E-\x7E]', string) is not None print("testing Chat validation") print(testChatChars("") == Fa

我试图进行一个非常简单的正则表达式匹配(对除“[”和“]”之外的所有可打印anscii字符求反)。我得到了我想要的匹配。然后我转到python单元测试,我的匹配永远不会返回true

def testChatChars(string):
   return re.match('[^\x20-\x5A\x5C\x5E-\x7E]', string) is not None

print("testing Chat validation") 
print(testChatChars("") == False)
print(testChatChars("this is a valid chat message") == True)
print(testChatChars("9999abcdefghijklmnopqrxtuvxyz ABCDEFGHIJKLMNOP!@#$(^&*(&%$^^)*)!{},.;'\|?/7") == True )
print(testChatChars("this is not [ valid chat message") == False)
print(testChatChars("this is not ] valid chat message") == False)
print(testChatChars("9999abcdefghijklmnopqrxtuvxyz [][][[][]ABCDEFGHIJKLMNOP!@#$(^&*(&%$^^)*)!{}[],.;'\|?/7ونِكود碼標準萬國") == False)
又回来了

False //should be true
False //should be true
False //should be true
True
True
True
由于某种原因,re.match总是不返回任何值

更新: 新的输出是

False
False
True
False
False
False

这对我有用。为什么我不需要^character,+$symbol做什么?@Rawrgulmuffins,我建议您阅读。公平地说,我只是(显然错误地)假设python正则表达式是perl正则表达式。
def testChatChars(string):
   return re.match(r'[\x20-\x5A\x5C\x5E-\x7E]+$', string) is not None