When I run this code:
print re.search(r'1', '1').groups()
I get a result of ()
. However, .group(0)
gives me the match.
Shouldn't groups()
give me something containing the match?
groups is empty since you do not have any capturing groups - http://docs.python.org/library/re.html#re.MatchObject.groups. group(0) will always returns the whole text that was matched regardless of if it was captured in a group or not
Edited.