Python 为什么match返回None而findall不返回';T

Python 为什么match返回None而findall不返回';T,python,regex,match,Python,Regex,Match,我有这个字符串: s = "mage('Images/mpins/pin5_Jul1.png', new" 这是我的模式: patt_img = r'\w+.png' 为什么 re.findall(patt_img,s) 返回 ['pin5_Jul1.png'] 但是match返回None m = re.match(patt_img,s) >>> type(m) <type 'NoneType'>` m=re.match(patt\u img,s) >>>

我有这个字符串:

s = "mage('Images/mpins/pin5_Jul1.png', new"
这是我的模式:

patt_img = r'\w+.png'
为什么

re.findall(patt_img,s)
返回

['pin5_Jul1.png']
但是
match
返回
None

m = re.match(patt_img,s)
>>> type(m)
<type 'NoneType'>`
m=re.match(patt\u img,s)
>>>类型(m)
`

因为
匹配
仅从字符串开头开始匹配

如果字符串开头的零个或多个字符与正则表达式模式匹配,则返回相应的
MatchObject
实例

如果要在字符串中的任何位置查找匹配项,请改用
search()


嗯,对。我总是忘记这件事。谢谢