From: Alan Mackenzie <acm@muc.de>
To: "Clément Pit--Claudel" <clement.pit@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Documentation on debugging regexp performance
Date: Thu, 21 Jan 2016 17:16:07 +0000 [thread overview]
Message-ID: <20160121171607.GC1795@acm.fritz.box> (raw)
In-Reply-To: <56A1095C.2070107@gmail.com>
Hello again Clément.
On Thu, Jan 21, 2016 at 11:37:48AM -0500, Clément Pit--Claudel wrote:
> On 01/21/2016 10:27 AM, Alan Mackenzie wrote:
> Hi Alan!
> > " +[^:=]+ +:=?" is an ill-formed regexp - if you get lots of spaces in
> > a non-match, the Emacs regexp engine will try all possible ways of
> > matching these spaces before giving up. You have three concatenated
> > sub-expressions, all of which match any number of spaces, namely:
> > " +[^:=]+ +"
> > 1122222233
> > I would suggest reformulating it thus:
> > " +[^:= ][^:=]+ "
> > 112222223333334
> I think this has different semantics: my original regexp requires at
> least three spaces. But I think prepending spaces to yours fixes that.
Sorry, yes, I'd extracted the interesting bit of your regexp, and forgot
that I'd done so.
> > Subexpression 1 matches ALL the leading spaces.
> > Subexp 2 is exactly one
> > character which can't be a space. Subexp 3 matches almost anything,
> > including spaces, and subexp 4 matches a single space at the end (to make
> > sure there is at least one space there).
> This is helpful, thanks! I realize however that maybe I
> oversimplified. The issue is that what I really want is something like
> this:
> " +\\([^:=]+\\) +:=?"
> IOW, I want to capture that first group.
That is ambiguous. But if we can assume that the first group always
begins with a non-space, and always ends with a non-space, then we can
reformulate the above as:
" +\\([^:= ]\\([^:=]+[^:= ]\\)?\\) +:=?"
^
(or something similar - I've not actually tested it). The ? inside the
first expression is to cope with there just being 1 single character
matched by the group.
> > All the best with your regexp!
> Thanks. Your points about backtracking were helpful as well. Do you
> know if there are technical reasons why Emacs chooses a backtracking
> implementation for this regexp (instead of compiling it to a
> linear-time matcher)?
I'm afraid I don't know. It might be that compiling a regexp for a
linear-time matcher would be slower. Or, possibly, nobody has sat down
and hacked out a better regexp engine.
> Clément.
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2016-01-21 17:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-21 5:29 Documentation on debugging regexp performance Clément Pit--Claudel
2016-01-21 6:36 ` Yuri Khan
2016-01-21 9:39 ` Alexis
2016-01-21 13:22 ` Clément Pit--Claudel
2016-01-21 22:10 ` Marcin Borkowski
2016-01-22 7:02 ` Alexis
2016-01-22 14:32 ` Clément Pit--Claudel
2016-01-21 11:42 ` Wolfgang Jenkner
2016-01-21 16:38 ` Clément Pit--Claudel
2016-01-21 15:27 ` Alan Mackenzie
2016-01-21 16:37 ` Clément Pit--Claudel
2016-01-21 17:16 ` Alan Mackenzie [this message]
2016-01-23 6:12 ` 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=20160121171607.GC1795@acm.fritz.box \
--to=acm@muc.de \
--cc=clement.pit@gmail.com \
--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.