From: aa8vb at vislab.epa.gov (Randall Hopper)
Date: Mon, 5 Apr 1999 12:48:19 GMT
Subject: Possible regex match bug (re module)
Message-ID: <19990405084819.B802985@vislab.epa.gov>
X-UID: 295                                                  

     Re doesn't handle named groups in alternative patterns like it seems
it should.  Given an alternative pattern with a particular group name in
each, it only assigns the match if the group name matches the last
alterative.

For example, the following example outputs:

  None
  def

rather than:

  abc
  def

(Note that I've simplified this example a good bit so the behavior is
apparent.)

Randall

-------------------------------------------------------------------------------

import re

pattern = '(---(?P<id>[^-]*)---)|(===(?P<id>[^=]*)===)'

s = "---abc---"
match = re.compile( pattern ).match(s,0)
print match.group('id')

s = "===def==="
match = re.compile( pattern ).match(s,0)
print match.group('id')




