bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#29343: 27.0.50; Match data doesn't contain elements for non-matched


From: Philipp Stephani
Subject: bug#29343: 27.0.50; Match data doesn't contain elements for non-matched subgroups
Date: Sat, 16 Dec 2017 14:29:12 +0000



Philipp Stephani <address@hidden> schrieb am Fr., 17. Nov. 2017 um 21:12 Uhr:

$ 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).


It turns out that this is harder than I expected, because the information about the number of groups in the pattern isn't stored anywhere, and search_regs.num_regs may be different from the group count. If it turns out too hard to fix, the behavior should at least be documented.

reply via email to

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