| 1197 | /** @internal */ |
| 1198 | _replaceRegexp(searchValue: RegExp, replacement: string | ReplacementFunction): this { |
| 1199 | function getReplacement(match: RegExpMatchArray, str: string): string { |
| 1200 | if (typeof replacement === 'string') { |
| 1201 | return replacement.replace(/\$(\$|&|\d+)/g, (_: string, i: string) => { |
| 1202 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter |
| 1203 | if (i === '$') |
| 1204 | return '$' |
| 1205 | if (i === '&') |
| 1206 | return match[0] |
| 1207 | const num = +i |
| 1208 | if (num < match.length) |
| 1209 | return match[+i] |
| 1210 | return `$${i}` |
| 1211 | }) |
| 1212 | } |
| 1213 | else { |
| 1214 | return replacement(match[0], ...match.slice(1), match.index, str, match.groups) |
| 1215 | } |
| 1216 | } |
| 1217 | function matchAll(re: RegExp, str: string): RegExpExecArray[] { |
| 1218 | const matches = [] |
| 1219 | while (true) { |