Updated: July 2009
Substitutions are allowed only within replacement patterns. For similar functionality within regular expressions, use a backreference (for example, \1). For details on backreferences, see Backreferences and Backreference Constructs.
Substitutions are the only special constructs recognized in a replacement pattern. For example, the replacement pattern a*${txt}b inserts the string "a*" followed by the substring matched by the txt capturing group, if any, followed by the string "b". The * character is not recognized as a metacharacter within a replacement pattern. Similarly, $ patterns are not recognized within regular expression matching patterns. Within regular expressions, $ designates the end of the string.
The following table shows how to define named and numbered replacement patterns.
Character | Description |
|---|
$number | Substitutes the last substring matched by group number number (decimal). |
${name} | Substitutes the last substring matched by a (?<name> ) group. |
$$ | Substitutes a single "$" literal. |
$& | Substitutes a copy of the entire match itself. |
$` | Substitutes all the text of the input string before the match. |
$' | Substitutes all the text of the input string after the match. |
$+ | Substitutes the last group captured. |
$_ | Substitutes the entire input string. |
Other Resources
Date | History | Reason |
|---|
July 2009
| Noted that character escapes are not supported in replacement strings. |
Customer feedback.
|