The groups () method in regular expressions in Python

I am learning regular expression in Python and I am having trouble understanding a function groups().

>>> m = re.match("([abc])+", "abc")

Here I defined the class [abc], which, as I know, means any of the characters from a to c. It is defined within the group, and the + sign means that we want at least one of these groups. So I execute the following line, and the result is clear:

>>> m.group()
'abc'
>>> m.group(0)
'abc'

I understand why this is happening. The index of the main group is 0, and "abc" corresponds to the class that we defined. So far, so good, but I don’t understand why the following lines are executed the way they do:

>>> m.group(1)
'c'
>>> m.groups()
('c',)

(1), "c"? , ? , "abc".

+4
2

re docs. :

group(0) , abc, 3 a, b c

group(i) i'th

,

, group(1) , c

+ , [abc] , + :

>>> re.match("([abc])", "abc").groups()
('a',)
>>> re.match("([abc]+)", "abc").groups()
('abc',)
+8

docs:

, :

>>> m = re.match(r"(..)+", "a1b2c3")  # Matches 3 times.
>>> m.group(1)                        # Returns only the last match.
'c3'

, c - .

, 'abc' - , , + :

>>> m = re.match("([abc]+)", "abc")
+1

All Articles