A replacement pattern is a string with parts of the match inserted or replaced It is inserted in the place of the matching portion of the input string. The rest of the string is left unchanged.

Substitution tokens:

$$ A literal "$"
$1 - $n The value of a numbered capture group
${name} The value of a named capture group
$& The whole (outermost) match
$` The input string before the match
$' The input string after the match
$+ The last group that was captured
$_ The entire input string

 

Examples

Input       Pattern               Replacement     Result
...........................................................
one two     ne t                                  owo
one two     e t                   _               on_wo
one two     (\w*)\s(\w*)          $2 $1           two one
one two     (?'a'\w*)\s(?'b'\w*)  ${b} ${a}       two one
one two     e\s[a-z]              $&$&            one te two
one two     \stw                  $`              oneoneo
one two     \stw                  $'              oneoo
oneeetwo    e+(two)               $+              ontwo
abcde       bc                    $_              aabcdede
ab(cd)ef    cd                    $_              ab(ab(cd)ef)ef

Last edited Sep 19, 2012 at 9:17 PM by SethMorris, version 2

Comments

No comments yet.