Is there a maximum length of a regular expression in python?

Roy Smith roy at panix.com
Fri Jan 20 21:42:54 EST 2006


In article <7xhd7yb9ya.fsf at ruckus.brouhaha.com>,
 Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

> Steve Holden <steve at holdenweb.com> writes:
> > > Does no one care about an internal error in the regular expression
> > > engine?
> > >
> > Not one that requires parsing a 100 kilobyte re that should be
> > replaced by something more sensible, no.
> 
> If the internal error means the re engine bumped into some internal
> limit and gracefully raised an exception, then fine.  If "internal
> error" means the re engine unexpectedly got into some inconsistent
> internal state, then threw up its hands and barfed after discovering
> the error sometime later, that's bad.  Does nobody care which it is?

The nice thing about an open source project is that if nobody else gets 
excited about some particular issue which is bothering you, you can take a 
look yourself.

(from Python-2.3.4/Modules/_sre.c):

static void
pattern_error(int status)
{
    switch (status) {
    case SRE_ERROR_RECURSION_LIMIT:
        PyErr_SetString(
            PyExc_RuntimeError,
            "maximum recursion limit exceeded"
            );
        break;
    case SRE_ERROR_MEMORY:
        PyErr_NoMemory();
        break;
    default:
        /* other error codes indicate compiler/engine bugs */
        PyErr_SetString(
            PyExc_RuntimeError,
            "internal error in regular expression engine"
            );
    }
}

I suppose one man's graceful exit is another man's barf.



More information about the Python-list mailing list