| 1 |
// Copyright 2017 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Named groups may be accessed in their replacement string by number |
| 6 |
esid: sec-getsubstitution |
| 7 |
features: [regexp-named-groups] |
| 8 |
info: | |
| 9 |
Runtime Semantics: GetSubstitution( matched, str, position, captures, namedCaptures, replacement ) |
| 10 |
|
| 11 |
Table: Replacement Text Symbol Substitutions |
| 12 |
|
| 13 |
Unicode Characters: $n |
| 14 |
Replacement text: |
| 15 |
The nth element of captures, where n is a single digit in the range 1 to 9. If |
| 16 |
n≤m and the nth element of captures is undefined, use the empty String instead. |
| 17 |
If n>m, the result is implementation-defined. |
| 18 |
---*/ |
| 19 |
|
| 20 |
let source = "(?<fst>.)(?<snd>.)|(?<thd>x)"; |
| 21 |
for (let flags of ["g", "gu"]) { |
| 22 |
let re = new RegExp(source, flags); |
| 23 |
assert.sameValue("badc", "abcd".replace(re, "$2$1")); |
| 24 |
} |
| 25 |
for (let flags of ["", "u"]) { |
| 26 |
let re = new RegExp(source, flags); |
| 27 |
assert.sameValue("bacd", "abcd".replace(re, "$2$1")); |
| 28 |
} |
| 29 |
|