temporary_user_name
temporary_user_name

Reputation: 37038

Why does this return an empty tuple?

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

Answers (1)

eumiro
eumiro

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

Related Questions