I'm trying to transform a rather long sequence of values to a different format, using emacs' replace-regex command. There are more than 9 values to extract, so the \1 - \9 back references are not enough.

How can I back reference more than 9 capture groups in emacs? Can named groups be used? If so, how?

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

Since Emacs 23, you can include Lisp code in a regexp replacement text. This gives you a way of using more backreferences. The function match-string returns the numbered backreferences.

\1 … \9 \,(or (match-string 10) "")

Since Emacs 22, if there's any parenthesized group in the regexp that you don't need to have a backreference for, use \(?:…\) (Emacs calls this a shy group).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.