I'm trying to understand a seemingly easy case while learning regular expressions.
Suppose I have a code like this:
import re
a = "Eventin queue contains 5 elements, first element is 20 minutes old"
b = re.search(r"Eventin queue contains \d+ elements, first element is \d+ minutes old", a)
print(b)
For some reason, b
only returns this result: <_sre.SRE_Match object; span=(0, 66), match='Eventin queue contains 5 elements, first element >
As you can see, it's not a full result that I was expecting. However, if I use re.findall()
I get ['Eventin queue contains 5 elements, first element is 20 minutes old']
Am I misunderstanding something here? Shouldn't re.search()
return the full match as well?