Title: Unable to match long strings with re
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7, Jython 2.5
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: amak, fwierzbicki, jeff.allen, thatch, zyasoft
Priority: normal Keywords:

Created on 2012-08-28.15:42:27 by thatch, last changed 2018-03-07.19:12:32 by jeff.allen.

msg7432 (view) Author: Tim Hatch (thatch) Date: 2012-08-28.15:42:26
I found this out in Pygments, where we use some alternations to match long strings/comments/etc in one go.  Someone else (with a similar use case) has found this same problem at

To reproduce:

>>> x = re.compile(r'a+')
>>> x.match('a' * 22000) 
<org.python.modules.sre.MatchObject object at 0x2>

Simply adding a grouping operator breaks it.

>>> x = re.compile(r'(?:a)+')
>>> x.match('a' * 22000)     
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion limit exceeded

With [Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_31
msg9500 (view) Author: Jim Baker (zyasoft) Date: 2015-02-08.06:01:09
Bug is still present in 2.7.0 trunk. We need to revisit our port of SRE.

Target 2.7.1 or later
msg11760 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-07.19:12:32
Still present:

PS bugs> jython
Jython 2.7.2a1+ (default:d74f8c2cd56f, Feb 24 2018, 17:18:53)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_151
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> m = re.compile(r'a+')
>>> m.match('a' * 22000)
<org.python.modules.sre.MatchObject object at 0x2>
>>> m = re.compile(r'(?:a)+')
>>> m.match('a' * 22000)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion limit exceeded
Date User Action Args
2018-03-07 19:12:32jeff.allensetnosy: + jeff.allen
messages: + msg11760
milestone: Jython 2.7.2 ->
2015-12-29 23:55:26zyasoftsetmilestone: Jython 2.7.1 -> Jython 2.7.2
2015-04-20 21:06:09zyasoftsetmilestone: Jython 2.7.1
2015-02-08 06:01:09zyasoftsetnosy: + zyasoft
messages: + msg9500
2014-09-26 05:46:30zyasoftsetresolution: accepted
2013-02-19 21:40:40fwierzbickisetpriority: normal
nosy: + fwierzbicki
versions: + Jython 2.5, Jython 2.7, - 2.5.3b1, 2.7a2
2012-08-28 22:03:55amaksetnosy: + amak
2012-08-28 15:42:27thatchcreate