Replacement Patterns
The characters in the following table have special meaning only in replacement patterns, used for example in editing, when searching for and replacing text.
Character | Pattern |
|---|---|
\ | Turn off the special meaning of the following character. |
\n | Reuse the text matched by the nth subpattern previously saved by \( and \) as part of the replacement pattern. n is a number from 1 to 9, with 1 starting on the left. |
& | Reuse the text matched by the search pattern as part of the replacement pattern. |
~ | Reuse the previous replacement pattern in the current replacement pattern. Must be the only character in the replacement pattern (ex and vi). |
% | Reuse the previous replacement pattern in the current replacement pattern. Must be the only character in the replacement pattern (ed). |
\u | Convert the first character of replacement pattern to uppercase. |
\U | Convert the entire replacement pattern to uppercase. |
\l | Convert the first character of replacement pattern to lowercase. |
\L | Convert the entire replacement pattern to lowercase. |
\e | Turn off previous \u or \l. |
\E | Turn off previous \U or \L. |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access