I am learning the re module and have a problem understanding re.search and re.match. The documentation gives a good example so I decided to try these out:
>>> import re
>>> pattern = re.compile('\d*')
>>> string = "123"
>>> pattern.match(string)
<_sre.SRE_Match object; span=(0, 3), match='123'>
>>> pattern.search(string)
<_sre.SRE_Match object; span=(0, 3), match='123'>
No surprises here, so I change the string a little:
>>> string = "hello 123"
>>> pattern.match(string)
<_sre.SRE_Match object; span=(0, 0), match=''>
>>> pattern.search(string)
<_sre.SRE_Match object; span=(0, 0), match=''>
Why is nothing found with the last call of search? I would expect it return something like this (a non-empty match object):
<_sre.SRE_Match object; span=(6, 9), match='123'>
What happens during that last call to search? Python 3.4.3