Re: match groups: optional groups not accessible

2005-06-10 Thread David Reitter
On 10 Jun 2005, at 20:38, Michael Chermside wrote: > David Reitter writes: > >> Why does the following result in an IndexError? >> > [...] > > import re > m = re.match('(?Pmaybe)?yes', "yes") > m.group(1) > m.group('maybe') > >> Traceback (most recent call last): >> File

RE: match groups: optional groups not accessible

2005-06-10 Thread Michael Chermside
David Reitter writes: > Why does the following result in an IndexError? [...] > >>> import re > >>> m = re.match('(?Pmaybe)?yes', "yes") > >>> m.group(1) > >>> m.group('maybe') > Traceback (most recent call last): > File "", line 1, in ? > IndexError: no such group Because the name of the n

Re: match groups: optional groups not accessible

2005-06-10 Thread Peter Hansen
Peter Hansen wrote: > [EMAIL PROTECTED] wrote: > >> Why does the following result in an IndexError? >> I try to match an optional group, and then access it via its group >> name. The group happens to not participate in the match, but is >> obviously defined in the pattern. >> > m = re.match('(

Re: match groups: optional groups not accessible

2005-06-10 Thread Duncan Booth
david.reitter wrote: > So I would expect None rather than an IndexError, which is (only?) > supposed to occur "If a string argument is not used as a group name in > the pattern". That is exactly what does happen. > > I would expect named groups and numbered groups to be behave the same > way. >

Re: match groups: optional groups not accessible

2005-06-10 Thread Peter Hansen
[EMAIL PROTECTED] wrote: > Why does the following result in an IndexError? > I try to match an optional group, and then access it via its group > name. The group happens to not participate in the match, but is > obviously defined in the pattern. > m = re.match('(?Pmaybe)?yes', "yes") Uh, don'