emacs-devel
[Top][All Lists]
Advanced

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

Re: Explicitly numbered subgroups in regular expressions


From: Stefan Monnier
Subject: Re: Explicitly numbered subgroups in regular expressions
Date: Sun, 10 Jun 2007 09:44:13 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

>     What it does is add a new regexp syntax \(?<num>:<regexp>\) which is
>     like \(<regexp>\) except that it specifies explicitly the number of
>     the subgroup.  E.g. (and (string-match "\\(?3:a\\)" "a") (match-data))
>     returns (0 1 nil nil nil nil 0 1).  There is no backward compatibility
>     issue with this patch: such regexps are currently rejected as invalid.

> The feature seems useful, but how does this affect the numbering of
> groups that don't specify a number?

A subgroup that doesn't explicitly specify a number gets the "smallest
natural number larger than all previous ones".  I.e.

  (and (string-match "\\(?3:a\\)\\(b\\)" "ab") (match-data))

returns

  (0 2 nil nil nil nil 0 1 1 2)

since the second group gets number 4.

> That has to be done right, then documented in the two manuals.

Sure,


        Stefan




reply via email to

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