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
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
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('(
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.
>
[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'