Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

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.