+ 1
Why the answer to this question is 3?
What would be the result of len(match.groups()) of a match of (a)(b(?:c)(d)(?:e)) ? ******************* I tried it with this code : import re pattern = r"(a)(b(?:c)(d)(?:e))" match = re.match(pattern, "abcdef") if match: print(len(match.groups())) print(match.groups())
10 Answers
+ 17
5
+ 3
Correct Answer:
Any letter out of "abc", then any out of "def"
+ 2
The groups with ?: are non-matching groups. They won't show up in the match list. They are useful for grouping pieces of your re together which you don't necessarily want to capture in the match.
+ 1
In the string, you can see 5 groups, but 2 of these are "Non-capturing" groups and they are not included in the match.groups() tuple. This is why the length of match.groups() is equal to 5-2=3
0
5
0
5
0
5 group
0
5
- 1
3