In the first example ([abc])+ creates a group for each character a, b or c found. c is an explicit group because it is the last character that matches the regular expression:
>>> re.match("([abc])+", "abca").groups() ('a',)
In your second example, you create one group that matches one or more characters a, b, or c in a string. Thus, you create one group for abc . If we continue abc , the group will continue with the line:
>>> re.match("([abc]+)", "abca").groups() ('abca',)
In the third example, the regular expression searches for exactly one character, which is either a, a, or c. Since a is the first character in abc , you get a. This changes if we change the first character in the string:
>>> re.match("([abc])", "cba").group() 'c'
source share