我有这个正则表达式
但是在给出的python2.7中运行它None
,为什么呢?
>>> fo = re.match('\.(\d+)\.', '/players/player.34360.html')
>>> type(fo)
<type 'NoneType'>
>>>
re.match()
仅匹配字符串的开头。用途re.search
:
fo = re.search(r'\.(\d+)\.', r'/players/player.34360.html')
提示:在regex101.com中,您可以通过单击code generator
左侧的链接来获取Python,PHP和JavaScript的代码片段。您可以立即看到对于Python,应该使用search
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句