Reputation: 37038
s = "hello cats"
print(re.search(r"hello",s).groups())
This prints ()
.
According to the documentation, groups() returns an empty tuple if no matches were found. So why doesn't this match?
Upvotes: 0
Views: 306
Reputation: 212845
groups
returns matched groups. You did not define any:
s = "hello cats"
print(re.search(r"(he)l(lo)",s).groups())
prints ('he', 'lo')
Upvotes: 6