Lar*_*gas 2 python regex match
我有这个字符串:
s = "mage('Images/mpins/pin5_Jul1.png', new"
Run Code Online (Sandbox Code Playgroud)
这是我的模式:
patt_img = r'\w+.png'
Run Code Online (Sandbox Code Playgroud)
为什么
re.findall(patt_img,s)
Run Code Online (Sandbox Code Playgroud)
返回
['pin5_Jul1.png']
Run Code Online (Sandbox Code Playgroud)
但match返回None?
m = re.match(patt_img,s)
>>> type(m)
<type 'NoneType'>`
Run Code Online (Sandbox Code Playgroud)
因为match匹配只从字符串的开头开始。
如果string开头的零个或多个字符与正则表达式模式匹配,则返回相应的
MatchObject实例。如果要在字符串中的任何位置定位匹配项,请
search()改用。