GNU bug report logs - #29343
Match data doesn't contain elements for trailing non-matched subgroups

Previous Next

Package: emacs;

Reported by: Philipp Stephani <p.stephani2 <at> gmail.com>

Date: Fri, 17 Nov 2017 20:12:01 UTC

Severity: minor

Found in version 27.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #15 received at 29343 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: Philipp Stephani <p.stephani2 <at> gmail.com>
Cc: 29343 <at> debbugs.gnu.org
Subject: Re: bug#29343: 27.0.50;
 Match data doesn't contain elements for non-matched subgroups
Date: Fri, 16 Mar 2018 20:37:41 -0400
Philipp Stephani <p.stephani2 <at> gmail.com> writes:

> $ emacs -Q -batch -eval '(progn (string-match "^\\(a\\)?\\(b\\)\\(c\\)?$" "b") (print (match-data)))'
> (0 1 nil nil 0 1)
>
> Note that neither the `a` nor the `c` group matched, but there are
> entries for `a` in `match-data`, but not for `c`.  This makes working
> with the match data unnecessarily hard because its length depends on
> whether certain optional groups have matched or not.  I haven't seen any
> discussion about this behavior in either the manual or the docstring.  I
> think the match data in this case should be (0 1 nil nil 0 1 nil nil).

You can get that result by passing a list of the expected length as the
REUSE argument to match-data:

(progn
  (string-match "^\\(a\\)?\\(b\\)\\(c\\)?$" "b")
  (match-data t (make-list 8 nil)))
  ;=> (0 1 nil nil 0 1 nil nil)




This bug report was last modified 3 years and 117 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.