I have a regex which has nested group in it, the returned result does match my expectation, can anyone tell me why?
input_string = "(;A[B][D];B[C])"
regex_str = r'\(;([A-Z]+(\[\w+\])+)*(.*)\)'
result = re.findall(regex_str, input_string)
I expected the output to be:
[('A[B][D]', '[B][D]', ';B[C]')]
However, the actual output is:
[('A[B][D]', '[D]', ';B[C]')]
Why didn't (\[\w+\])+
match '[B][D]' instead of '[D]'?