1

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'>
>>>
Tjorriemorrie
  • 16,818
  • 20
  • 89
  • 131
  • http://stackoverflow.com/questions/180986/what-is-the-difference-between-pythons-re-search-and-re-match – Mazdak Apr 20 '15 at 13:22

1 Answers1

4

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.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563