Named capture groups in regular expressions (original) (raw)

Code units

Unicode Characters

Replacement text

0x0024, 0x0024

$$

$

0x0024, 0x0026

$&

matched

0x0024, 0x0060

$`

If position is 0, the replacement is the empty String. Otherwise the replacement is the substring of str that starts at index 0 and whose last code unit is at index position - 1.

0x0024, 0x0027

$'

If tailPos ≥ stringLength, the replacement is the empty String. Otherwise the replacement is the substring of str that starts at index tailPos and continues to the end of str.

0x0024, N
Where
0x0031 ≤ N ≤ 0x0039

$n where
n is one of 1 2 3 4 5 6 7 8 9 and $n is not followed by a decimal digit

The nth element of captures, where n is a single digit in the range 1 to 9. If n≤m and the nth element of captures is undefined, use the empty String instead. If n>m, the result is implementation-defined.

0x0024, N, N
Where
0x0030 ≤ N ≤ 0x0039

$nn where
n is one of 0 1 2 3 4 5 6 7 8 9

The nnth element of captures, where nn is a two-digit decimal number in the range 01 to 99. If nn≤m and the nnth element of captures is undefined, use the empty String instead. If nn is 00 or nn>m, no replacement is done.

0x0024, 0x003C

$<

  1. If namedCaptures is undefined, the replacement text is the String "$<".
  2. Otherwise,
    1. Scan until the next >.
    2. If none is found, the replacement text is the String "$<".
    3. Otherwise,
      1. Let the enclosed substring be groupName.
      2. Let capture be ? Get(namedCaptures, groupName).
      3. If capture is undefined, replace the text through > with the empty string.
      4. Otherwise, replace the text through this following > with ? ToString(capture).

0x0024

$ in any context that does not match any of the above.

$