Message68
There appears to be a bug either in MatchObject.java or in the regular
expression package (I've only tested using a distribution WITH
OROMatcher so far). For more complex regular expressions, it appears
that referencing a group in a match object by its name can cause an
IndexError. Following is a code snippet that demonstrates the
problem. I haven't been able to determine why exactly Case 3 works
whereas Case 1 fails inappropriately. Case 2 seems to fail
appropriately.
I have tested under all combinations of jdk 1.1/jdk 1.2 and jpython
1.1beta2/1.1beta3. The code snippet seems to behave as expected in
CPython.
-------------------------begin-----------------------------------
import re
# Regular expressions used for parsing
_S = '[ \t\r\n]+' # white space
_opS = '[ \t\r\n]*' # optional white space
_Name = '[a-zA-Z_:][-a-zA-Z0-9._:]*' # valid XML name
_QStr = "(?:'[^']*'|\"[^\"]*\")" # quoted XML string
attrfind = re.compile(
_S + '(?P<name>' + _Name + ')'
'(' + _opS + '=' + _opS +
'(?P<value>'+_QStr+'|[-a-zA-Z0-9.:+*%?!()_#=~]+))?')
starttagend = re.compile(_opS + '(?P<slash>/?)>')
## Case 1
starttagmatch = re.compile('<(?P<tagname>'+_Name+')'
'(?P<attrs>(?:'+attrfind.pattern+')*)'+
starttagend.pattern)
m = starttagmatch.match('<foo>')
try:
print '|%s|' % m.group('slash')
except IndexError, e:
print e
## Case 2
starttagmatch = re.compile('<(?P<tagname>'+_Name+')'
'(?P<attrs>(?:'+attrfind.pattern+')*)')
m = starttagmatch.match('<foo>')
try:
print '|%s|' % m.group('slash')
except IndexError, e:
print e
## Case 3
r = re.compile('<(?P<tagname>' + _Name + ')'
+ _opS + '(?P<slash>/?)>')
m = r.match('<foo>')
print '|%s|' % m.group('slash')
---------------------------end-----------------------------------
JPython output:
---------------
group 7 is undefined
group 'slash' is undefined
||
CPython output:
---------------
||
group 'slash' is undefined
||
|
|
Date |
User |
Action |
Args |
2008-02-20 17:16:39 | admin | link | issue222815 messages |
2008-02-20 17:16:39 | admin | create | |
|