我觀察到以下行爲在Python 2.7.5:Python re:爲什麼[,-_]匹配「=」?
>>> import re
>>> re.match(r'[,-_]', '=') # This matches
<_sre.SRE_Match object at 0x7f24d4981308>
>>> re.match(r'[-,_]', '=') # This doesn't match
>>> re.match(r'[-_,]', '=') # Nor does this
有人能解釋我所看到的嗎?我似乎無法找到任何關於,-_
在python正則表達式(或原始字符串)中的特殊用法。
[preg \ _match用戶名驗證正則表達式允許>和<儘管這些字符未被列入白名單]的可能重複(http://stackoverflow.com/questions/9996951/preg-match-username-validation-regex-allows-and -despite-those-characters-not) – Xufox