(emacs)Regexp Replace

Next: Replacement and Case Prev: Unconditional Replace Up: Replace

Regexp Replacement

   The `M-x replace-string' command replaces exact matches for a single
string.  The similar command `M-x replace-regexp' replaces any match
for a specified pattern.

   In `replace-regexp', the NEWSTRING need not be constant: it can
refer to all or part of what is matched by the REGEXP.  `\&' in
NEWSTRING stands for the entire text being replaced.  `\D' in
NEWSTRING, where D is a digit, stands for whatever matched the Dth
parenthesized grouping in REGEXP.  To include a `\' in the text to
replace with, you must give `\\'.  For example,

     M-x replace-regexp RET c[ad]+r RET \&-safe RET

replaces (for example) `cadr' with `cadr-safe' and `cddr' with

     M-x replace-regexp RET \(c[ad]+r\)-safe RET \1 RET

performs the inverse transformation.

automatically generated by info2www