Error in re-module?

ee webers at bigfoot.de
Wed May 10 15:14:53 EDT 2000


Hi,
I have some trouble with the re-module. I tried the follwing Perl-style
regular expression with Python 1.6 (cvs-checkout 20000510):

[PYTHON (1.6/cvs-version 20000510)]
> line = '"(" XYZ ")"'
> match = re.match('^(?P<token>"((\\")|[^"])*")(?P<data>.*)$', line)
[/PYTHON]

I expected to get:

match.group("token")     == '"("'
match.group("data")       ==  ' XYZ ")"'

But that's what I got:

match.group("token")     == '"(" XYZ ")"'
match.group("data")       ==  ''

I tried the same expression with Perl an got the expected result:

[PERL (5.004_04)]
 $line = "\"(\" Xbasdfz \")\"";
 $line =~ /^(\"((\\\")|[^\"])*\")(.*)$/;
 print "1 = $1\n2 = $2\n3 = $3\n4 = $4\n";
[/PERL]

[OUTPUT]
 1 = "("
 2 = (
 3 =
 4 =  Xbasdfz ")"
[/OUTPUT]

Any ideas?





More information about the Python-list mailing list