Export (0) Print
Expand All
1 out of 10 rated this helpful - Rate this topic

Substitutions 

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.

Character escapes and substitutions are the only special constructs recognized in a replacement pattern. All the syntactic constructs described in the following sections are allowed only in regular expressions; they are not recognized in replacement patterns. 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.