I have this regex
But running it in the python2.7 it gives None
, why is that?
>>> fo = re.match('\.(\d+)\.', '/players/player.34360.html')
>>> type(fo)
<type 'NoneType'>
>>>
I have this regex
But running it in the python2.7 it gives None
, why is that?
>>> fo = re.match('\.(\d+)\.', '/players/player.34360.html')
>>> type(fo)
<type 'NoneType'>
>>>
re.match()
only matches at the beginning of the string. Use re.search
:
fo = re.search(r'\.(\d+)\.', r'/players/player.34360.html')
A hint: in regex101.com, you can get code snippets in Python, PHP and JavaScript, by clicking on the code generator
link on the left. You could see at once that for Python, you should use search
.