>> This looks useful, but I think it would be even better to add it
>> as a pcase macro to be composable (see attached patch).
Hey, very nice. Please add it to rx.el.
[ But please change `backref-var` to just `backref` (you can distinguish
the two based on the type of the argument, I think). I guess one
could also argue that you could similarly rename the `let` to
`group-n`. ]
Pushed as ad4eff3b905dbc32e2d38bfec1e4f93eceec288d. I've renamed backref-var to backref as you suggested, but left `let' because I think that feature is important enough to deserve a short, common name.
> Although, i must admit i am not fluent in `rx' syntaxis, i find your idea
> very nice.
If you prefer the standard/cryptic regexp syntax, I posted a similar
thingy in the past (see below).
This lets you do
(pcase "foo-123"
((re-match "[[:alpha:]]+-\\(?num:[0-9]+\\)")
num))
=> "123"
Maybe I should install it in pcase.el?
Sure! I'd suggest to change the syntax to be compatible with other languages:
\(?<abc>[0-9]+\) or \(?'abc'[0-9+\) (Perl and .NET)
\(?P<abc>[0-9]+\) (Python)
These languages also have syntax for named backreferences, though that's less important.