I run into a problem where I need to capture all groups in a Kleene plus closure. I tried with another scenario and got the same behavior. So an example
(?:([A-Za-z]+) )+
for the string
This is a sentence.
I always get back the last match as a group instead of all the possible groups. In the case above, group(1) is a
and there are no other groups. I would want group(1) to be This
group(2) to be is
and group(3) a
. For the above I was using search
EDIT
Serves me right for not using the exact case I care about ...
\{([ A-Z]+)(?:\|([ A-Z]+))+\}
and
NBAR -> { AP NBAR | NBAR PP | VPG | N | N N }
In this case, findall
does not work. Using this online tool I get [(u' AP NBAR ', u' N N ')]
which is quite similar as to what groups()
would give me.