re.sub() has some difference result in CPython and IronPython
Below code has different result in IronPython 2.0A4 and Cpython, as follow:
re.sub('x', r'\111', 'x')
re.sub('x', r'\117', 'x')
re.sub('x', r'\1111', 'x')
re.sub('x', r'\1111', 'x')
re.sub('x', r'\400', 'x')
re.sub('x', r'\777', 'x')
re.sub('(((((((((((x)))))))))))', r'\11', 'x')
re.sub('((((((((((y))))))))))(.)', r'\118', 'xyz')
re.sub('((((((((((y))))))))))(.)', r'\11a', 'xyz')
Below code throws re.error in Cpython, but can run successfully in IronPython
2.0A4, as follow:
re.sub('x', r'\1', 'x')
re.sub('x', r'\8', 'x')
re.sub('x', r'\9', 'x')
re.sub('x', r'\11', 'x')
re.sub('x', r'\18', 'x')
re.sub('x', r'\1a', 'x')
re.sub('x', r'\90', 'x')
re.sub('x', r'\99', 'x')
re.sub('x', r'\118', 'x') # r'\11' + '8'
re.sub('x', r'\11a', 'x')
re.sub('x', r'\181', 'x') # r'\18' + '1'
re.sub('x', r'\800', 'x') # r'\80' + '0'
re.sub('(?Px)', '\gx)', '\gx)|(?Py)', '\2', 'xx')
Below code throws re.error in CPython, but throws IndexError in IronPython
2.0A4, as follow:
re.sub('(?Px)|(?Py)', '\g', 'xx')
re.sub('(?Px)', '\g', 'xx')
re.sub('(?Px)', '\g', 'xx')
re.sub('(?Px)', '\g', 'xx')
import re
re.sub('x', r'\111', 'x')
re.sub('x', r'\117', 'x')
re.sub('x', r'\1111', 'x')
re.sub('x', r'\1111', 'x')
re.sub('x', r'\400', 'x')
re.sub('x', r'\777', 'x')
re.sub('(((((((((((x)))))))))))', r'\11', 'x')
re.sub('((((((((((y))))))))))(.)', r'\118', 'xyz')
re.sub('((((((((((y))))))))))(.)', r'\11a', 'xyz')
re.sub('x', r'\1', 'x')
re.sub('x', r'\8', 'x')
re.sub('x', r'\9', 'x')
re.sub('x', r'\11', 'x')
re.sub('x', r'\18', 'x')
re.sub('x', r'\1a', 'x')
re.sub('x', r'\90', 'x')
re.sub('x', r'\99', 'x')
re.sub('x', r'\118', 'x') # r'\11' + '8'
re.sub('x', r'\11a', 'x')
re.sub('x', r'\181', 'x') # r'\18' + '1'
re.sub('x', r'\800', 'x') # r'\80' + '0'
re.sub('(?Px)', '\gx)', '\gx)|(?Py)', '\2', 'xx')
re.sub('(?Px)|(?Py)', '\g', 'xx')
re.sub('(?Px)', '\g', 'xx')
re.sub('(?Px)', '\g', 'xx')
re.sub('(?Px)', '\g', 'xx')
Work Item Details
Original CodePlex Issue: Issue 23751 Status: Active Reason Closed: Unassigned Assigned to: Unassigned Reported on: Jul 27, 2009 at 11:47 PM Reported by: dfugate Updated on: Feb 22, 2013 at 2:12 AM Updated by: jdhardy Custom value: Reported internally at Microsoft. Test: test_re.py CreatedDate: 9/25/2007 NewInternalID: 409543 OldInternalID: 305766 AreaPath: IronPython\Modules
Plaintext Attachments
On 2011-02-09 05:12:48 UTC, rjnienaber commented:
Cleaning up the script and executing it against CPython and IronPython 2.7b2 on .NET Version: 4.0.30319.1: python27 testcase-23751.py
Traceback (most recent call last):
File "C:\ipy\testcase-23751.py", line 12, in
line 151, in sub return _compile(pattern, flags).sub(repl, string, count) File "C:\ipy\main\External.LCA_RESTRICTED\Languages\IronPython\27\lib\re.py",
line 278, in filter return sre_parse.expand_template(template, match) File "C:\ipy\main\External.LCA_RESTRICTED\Languages\IronPython\27\lib\sre_pars
e.py", line 789, in expand_template raise error, "invalid group reference" sre_constants.error: invalid group reference ipy27 testcase-23751.py
Traceback (most recent call last):
File "C:\ipy\testcase-23751.py", line 24, in