In python, I can use regular expression like this:
prog = re.compile(pattern)
result = prog.match(string)
And I can result.groups(0), result.groups(0), … etc.
How can I find out how many groups in the result? I tried ‘len(result.groups)’, but I get:
TypeError: object of type 'builtin_function_or_method' has no len()
What you are trying is correct but you just missed the parentheses:
Try:
That should do the work. As the error suggests, you are trying to get the length of a function. What you want is the length of the value (in this case, a tuple) returned after the execution of the function.