+ 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())

5th Feb 2017, 6:53 PM
SADMI BOUHAFS
SADMI BOUHAFS - avatar
10 Answers
+ 17
5
29th Jul 2019, 10:01 AM
Rutuja Madnaik
Rutuja Madnaik - avatar
+ 3
Correct Answer: Any letter out of "abc", then any out of "def"
1st May 2020, 4:43 PM
Subba Rao Daggubati
Subba Rao Daggubati  - avatar
+ 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.
6th Feb 2017, 3:21 AM
Builderben
+ 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
15th Jul 2020, 4:34 PM
DonLarry
DonLarry - avatar
0
5
1st Jul 2018, 6:14 AM
RISHABH GUPTA
RISHABH GUPTA - avatar
0
5
12th Dec 2018, 8:07 AM
Rama Rao Pulumamidi
Rama Rao Pulumamidi - avatar
0
5 group
15th Mar 2019, 1:46 PM
Patil Virendra Sanjay
0
5
14th Jul 2019, 2:55 AM
Nareshpal
Nareshpal - avatar
- 1
3
12th Oct 2018, 10:18 PM
Youssef Alsoufi