[IronPython] Regex that works under CPython doesn't compile under IronPython

Dino Viehland dinov at exchange.microsoft.com
Fri Sep 8 22:36:32 CEST 2006

This is a bug - I've opened CodePlex bug #3049 to track this (http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=3049).

The problem here is that we're not recognizing the double \ as being a valid escape sequence that we should ignore.  Instead we skip the 1st \, see the \A and then believe we should remove the escaping for you.

If you'd like to fix this locally on your own copy you can add:

                    case '\\':
                        // escaping a \\

to the 2nd switch statement in PreParseRegex method (in Src\IronPython\Modules\re.cs).  Otherwise I've tentatively opened this as a 1.01 bug.  Thanks for the report!

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Chuck.Kirschman at bentley.com
Sent: Friday, September 08, 2006 5:24 AM
To: users at lists.ironpython.com
Subject: [IronPython] Regex that works under CPython doesn't compile under IronPython

import re

# compiles under CPython, fails under IronPython myregex = re.compile (r"[\\A-Z\.\+]")

if myregex.search ('aaaA\\B\\Caaa'):
        print 'found'
        print 'not found'


I tried to run my Python script under Iron Python and this line:

        re.compile (r"[\\A-Z\.\+]")

does not compile.  I get

        re.error: parsing "[\A-Z\.\+]" - Unrecognized escape sequence \A.

To fix it, I had to go to 3 slashes, not 2 or 4:

        re.compile (r"[\\\A-Z\.\+]")

This seems a bit counter-intuitive to me.


users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list