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

Chuck.Kirschman at bentley.com Chuck.Kirschman at bentley.com
Fri Sep 8 14:24:08 CEST 2006

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

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.  


More information about the Ironpython-users mailing list