Unconditional Replace Replace Replacement and Case
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 match 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 enter
`\\
'. For example,
M-x replace-regexpRET
c[ad]+rRET
\&-safeRET
replaces (for example) `cadr
' with `cadr-safe
' and `cddr
'
with `cddr-safe
'.
M-x replace-regexpRET
\(c[ad]+r\)-safeRET
\1RET
performs the inverse transformation.
Unconditional Replace Replace Replacement and Case