2016-12-11 30 views
2

作爲一個更大的代碼我想檢查是否字符串(文件名)結尾部分結束串「數」 然而,re.match( re.compile和match)不會匹配字符串末尾的模式。Python的re.match不匹配帶「數」

代碼:

import re 
f = ".1.txt.2" 
print re.match('\.\d$',f) 

輸出:

>>> print re.match('\.\d$',f) 
None 

任何幫助將非常感激!使用替代

+0

可能重複的[Python正則表達式re.match,爲什麼此代碼不起作用?](http://stackoverflow.com/questions/14933771/python-regular-expression-re-match-why-this -code - 不 - 不工作) – rock321987

回答