I am working with regular expressions and am struggling to understand a particular output.
Case 1:
>>> m = re.match("(abc)+", "abc")
>>> m.groups()
('abc',)
Case 2:
>>> m = re.match("([abc])+", "abc")
>>> m.groups()
('c',)
In Case 1 above, I do understand how m.groups()
returns ('abc',)
(a tuple with the matched string for group 1, the only group in the RE).
However, in Case 2 above, where I put 'abc' in the RE inside a character class as [abc]
, I do not understand why does m.groups()
return ('c',)
. I would have still expected the same tuple returned as Case 1, i.e. ('abc',)
Could anyone please help me understand why does m.groups()
return ('c',)
in Case 2.