len(match.groups()) of a match of (a)(b(?:c)(d)(?:e))? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

len(match.groups()) of a match of (a)(b(?:c)(d)(?:e))?

explain this please? len(match.groups()) of a match of (a)(b(?:c)(d)(?:e))?

6th Jan 2017, 11:13 AM
Sanjiv Jaiswal
Sanjiv Jaiswal - avatar
14 Answers
+ 12
the ans of this Q's is to be 3
15th Aug 2017, 1:19 PM
Sagar Upadhyay
Sagar Upadhyay - avatar
+ 4
import re test = re.compile('(a)(b(?:c)(d)(?:e))') match = test.search('abcde') match.groups() ('a', 'bcde', 'd') len(match.groups()) answer is 3
15th Sep 2017, 4:21 PM
Stanley
Stanley - avatar
+ 2
You might want to check your regexp code with https://regex101.com/#JUMP_LINK__&&__python__&&__JUMP_LINK. It is an incredibly useful site! Normally a () will return a group with the contents within. ( followed by a ?:, will create a non-capturing group, but will still match any character(s) behind it. in this case (?:c) (a) = group1 (b......e) = group2 (d) = group3 so the length of it all is 3. >>> import re >>> test = re.compile('(a)(b(?:c)(d)(?:e))') >>> match = test.search('abcde') >>> match.groups() ('a', 'bcde', 'd') >>> len(match.groups()) 3
7th Jan 2017, 10:05 PM
Bart Dorlandt
Bart Dorlandt - avatar
+ 1
Question :- What would be the result of len(match.groups()) of a match of (a)(b(?:c)(d)(?:e))? import re test = re.compile('(a)(b(?:c)(d)(?:e))') match = test.search('abcde') match.groups() ('a', 'bcde', 'd') len(match.groups()) Answer:- 3
29th Jun 2020, 6:13 AM
Gourav Tomar
Gourav Tomar - avatar
0
They are regular expresions. Im not really into python, but len its for length of the group, wich can follow that rule/regular expresion. And it match "abcde".
6th Jan 2017, 11:40 AM
Nahuel
Nahuel - avatar
0
Great copy paste Stanley! The best way to learn. Keep up the good work.
24th Sep 2017, 4:57 PM
Bart Dorlandt
Bart Dorlandt - avatar
0
dontknow
18th Feb 2018, 11:05 AM
Prashant Agrawal
0
3
25th Sep 2019, 3:07 PM
Tuyishime Sosthen
Tuyishime Sosthen - avatar
0
Answer is 3
14th Mar 2020, 5:52 PM
Moise DIARRA
Moise DIARRA - avatar
0
What would be the result of len(match.groups()) of a match of (a)(b(?:c)(d)(?:e))? 3
15th Mar 2020, 4:03 AM
sivaguru y v
sivaguru y v - avatar
0
3
8th Jun 2020, 8:48 AM
gashaw desalegn
gashaw desalegn - avatar
0
3
13th Jul 2020, 3:57 AM
Ryan Wilke
Ryan Wilke - avatar
0
ans should be 3
5th Feb 2021, 3:09 AM
Sachin Sisodia
Sachin Sisodia - avatar
- 1
answer is 5
15th Mar 2020, 10:10 AM
P.Sai Shanmitha
P.Sai Shanmitha - avatar