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))?
14 Respostas
+ 12
the ans of this Q's is to be 3
+ 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
+ 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
+ 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
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".
0
Great copy paste Stanley! The best way to learn. Keep up the good work.
0
dontknow
0
3
0
Answer is 3
0
What would be the result of len(match.groups()) of a match of (a)(b(?:c)(d)(?:e))?
3
0
3
0
3
0
ans should be 3
- 1
answer is 5