From: Alan Mackenzie <acm@muc.de>
To: emacs-devel@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: Re: Fixing ill-conditioned regular expressions. Proof of concept.
Date: Thu, 26 Feb 2015 13:09:18 +0000 [thread overview]
Message-ID: <20150226130917.GC19320@acm.fritz.box> (raw)
In-Reply-To: <87fv9tc4qm.fsf@gnu.org>
Hello, Tassilo.
On Thu, Feb 26, 2015 at 12:05:37PM +0100, Tassilo Horn wrote:
> Alan Mackenzie <acm@muc.de> 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\)\)
> ?
Thanks. That's a brilliant idea! I think it would work.
> As long as the groups with the same number are exclusive there shouldn't
> be a problem.
I think that's true. There might be a slight problem with groups which
match only the empty string. Something like:
R*\(\)R*
, but anybody who writes such regexps deserves what she gets.
> Bye,
> Tassilo
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2015-02-26 13:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-23 18:12 Fixing ill-conditioned regular expressions. Proof of concept Alan Mackenzie
2015-02-23 19:55 ` Paul Eggert
2015-02-23 20:21 ` Alan Mackenzie
2015-02-23 22:19 ` Paul Eggert
2015-02-23 22:42 ` Alan Mackenzie
2015-02-23 23:07 ` Artur Malabarba
2015-02-23 23:37 ` Paul Eggert
2015-02-25 10:08 ` Alan Mackenzie
2015-02-26 1:11 ` Stephen J. Turnbull
2015-02-26 8:46 ` Paul Eggert
2015-02-26 10:11 ` Alan Mackenzie
2015-02-26 11:05 ` Tassilo Horn
2015-02-26 13:09 ` Alan Mackenzie [this message]
2015-02-26 13:46 ` Stefan Monnier
2015-02-26 16:21 ` Alan Mackenzie
2015-02-26 19:12 ` Stefan Monnier
2015-02-26 20:01 ` Alan Mackenzie
2015-02-27 13:45 ` Stefan Monnier
2015-02-24 16:29 ` Stefan Monnier
2015-02-24 6:20 ` Philipp Stephani
2015-03-13 22:53 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150226130917.GC19320@acm.fritz.box \
--to=acm@muc.de \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.