Runtime Semantics: GetSubstitution ( _matched_, _str_, _position_, _captures
- 0x0024, N
-
- Where
-
- 0x0031 ≤ N ≤ 0x0039
+ 0x0024, 0x0030
|
- `$n` where
-
- `n` is one of `1 2 3 4 5 6 7 8 9` and `$n` is not followed by a decimal digit
+ `$0`
|
- The _n_th element of _captures_, where _n_ is a single digit in the range 1 to 9. If _n_ ≤ _m_ and the _n_th element of _captures_ is *undefined*, use the empty String instead. If _n_ > _m_, no replacement is done.
+ `$0`
|
- 0x0024, N, N
-
- Where
+ 0x0024, N
- 0x0030 ≤ N ≤ 0x0039
+ where 0x0031 ≤ N ≤ 0x0039
|
- `$nn` where
-
- `n` is one of `0 1 2 3 4 5 6 7 8 9`
+ `$`_n_
+ where _n_ is an expansion of |NonZeroDigit|
|
- The _nn_th element of _captures_, where _nn_ is a two-digit decimal number in the range 01 to 99. If _nn_ ≤ _m_ and the _nn_th element of _captures_ is *undefined*, use the empty String instead. If _nn_ is 00 or _nn_ > _m_, no replacement is done.
+ If the MV of _n_ > _m_, the replacement is the matched code units (equivalent to no replacement).
+
+ Otherwise, if the element in _captures_ at index equal to the MV of _n_ minus 1 is *undefined*, the replacement is the empty String.
+
+ Otherwise, the replacement is the element in _captures_ at index equal to the MV of _n_ minus 1.
|
- 0x0024, 0x003C
+ 0x0024, N1, N2
+
+ where 0x0030 ≤ N1 ≤ 0x0039 and 0x0030 ≤ N2 ≤ 0x0039
|
- `$<`
+ `$`_nn_
+ where _nn_ is a two-element expansion of |DecimalDigits|
|
-
- 1. If _namedCaptures_ is *undefined*, the replacement text is the String `"$<"`.
- 1. Else,
- 1. Scan until the next `>` U+003E (GREATER-THAN SIGN).
- 1. If none is found, the replacement text is the String `"$<"`.
- 1. Else,
- 1. Let _groupName_ be the enclosed substring.
- 1. Let _capture_ be ? Get(_namedCaptures_, _groupName_).
- 1. If _capture_ is *undefined*, replace the text through `>` with the empty string.
- 1. Otherwise, replace the text through `>` with ? ToString(_capture_).
-
+ If _nn_ is `00` or the MV of _nn_ > _m_, the replacement is the string-concatenation of the replacement for the first two matched code units (i.e., a replacement specified by one of the two preceding rows) and the remaining matched code units (i.e., a single |DecimalDigit|).
+
+ Otherwise, if the element in _captures_ at index equal to the MV of _nn_ minus 1 is *undefined*, the replacement is the empty String.
+
+ Otherwise, the replacement is the element in _captures_ at index equal to the MV of _nn_ minus 1.
|
- 0x0024
+ 0x0024, 0x003C, any sequence of code units not containing 0x003E, 0x003E
|
- `$` in any context that does not match any of the above.
+ `$<` _groupName_ `>`
+ where _groupName_ is a sequence of code units that does not contain a `>` U+003E (GREATER-THAN SIGN)
|
- `$`
+
+ 1. Set _groupName_ to the String value whose code units are the code units of _groupName_.
+ 1. If _namedCaptures_ is *undefined*, then
+ 1. The replacement is the string-concatenation of the String `"$<"`, ! GetSubstitution(_matched_, _str_, _position_, _captures_, _namedCaptures_, _groupName_), and the String `">"`.
+ 1. Else,
+ 1. Let _capture_ be ? Get(_namedCaptures_, _groupName_).
+ 1. If _capture_ is *undefined*, the replacement is the empty String. Otherwise, the replacement is ? ToString(_capture_).
+
|