While reading the docs, I found out that the whole difference between re.match()
and re.search()
is that re.match()
starts checking only from the beginning of the string.
>>> import re
>>> a = 'abcde'
>>> re.match(r'b', a)
>>> re.search(r'b', a)
<_sre.SRE_Match object at 0xffe25c98>
>>> re.search(r'^b', a)
>>>
Is there anything I am misunderstanding, or is there no difference at all between re.search('^' + pattern)
and re.match(pattern)
?
Is it a good practice to only use re.search()
?