all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Philipp Stephani <p.stephani2@gmail.com>
Cc: 29343@debbugs.gnu.org
Subject: bug#29343: 27.0.50; Match data doesn't contain elements for non-matched subgroups
Date: Fri, 19 Apr 2019 14:29:27 -0400	[thread overview]
Message-ID: <87muklvofs.fsf@gmail.com> (raw)
In-Reply-To: <CAArVCkS9kW6VBg4kbpodzS-dkAX9LK8uZyTr67Bw8=28j617gA@mail.gmail.com> (Philipp Stephani's message of "Fri, 19 Apr 2019 20:22:23 +0200")

Philipp Stephani <p.stephani2@gmail.com> writes:

> Am Sa., 17. März 2018 um 01:37 Uhr schrieb Noam Postavsky <npostavs@gmail.com>:
>>
>> Philipp Stephani <p.stephani2@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:
>
> True, but that also requires knowing the expected length. In the most
> general case this should work for unknown regular expressions.

I don't understand how the general case you describe could occur.  If
you don't know the expected length, that means you don't what groups are
in the regexp, so you can only rely on group 0 existing, i.e., you only
care about the first two elements in the match-data.






  reply	other threads:[~2019-04-19 18:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-17 20:11 bug#29343: 27.0.50; Match data doesn't contain elements for non-matched subgroups Philipp Stephani
2017-12-16 14:29 ` Philipp Stephani
2022-01-29 15:40   ` bug#29343: Match data doesn't contain elements for trailing " Lars Ingebrigtsen
2018-03-17  0:37 ` bug#29343: 27.0.50; Match data doesn't contain elements for " Noam Postavsky
2019-04-19 18:22   ` Philipp Stephani
2019-04-19 18:29     ` Noam Postavsky [this message]
2019-04-19 18:42       ` Philipp Stephani
2019-04-19 18:54         ` Noam Postavsky

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=87muklvofs.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=29343@debbugs.gnu.org \
    --cc=p.stephani2@gmail.com \
    /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.