emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fixing ill-conditioned regular expressions. Proof of concept.


From: Tassilo Horn
Subject: Re: Fixing ill-conditioned regular expressions. Proof of concept.
Date: Thu, 26 Feb 2015 12:05:37 +0100
User-agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux)

Alan Mackenzie <address@hidden> writes:

Hi Alan,

>> Sure, but you could remember how the \(...\) constructs were
>> renumbered, and fix the match data after the underlying regexp call
>> returned.  It shouldn't be a big deal.
>
> Unfortunately, it's not that simple.  Consider the RE
>
>     \(R\)+E*\(R\)+
>      1  1    2  2
>
> .  This gets transformed to
>
>     \(R\)+\(?:E+\(R\)+\|\(R\)\)
>      1  1        2  2    2  2
>
> .  What was subexpression 2 in the original has become two
> subexpressions straddling an \| sign in the transformation.  I don't
> think there's a way of transforming R+E*R+ that preserves the
> numbering of the subexpressions.

Couldn't you use explicitly numbered groups, i.e., the regex would
translate to

    \(?1:R\)+\(?:E+\(?2:R\)+\|\(?2:R\)\)

?

As long as the groups with the same number are exclusive there shouldn't
be a problem.

Bye,
Tassilo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]