Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 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).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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