| 816 | |
| 817 | _replaceRegexp(searchValue, replacement) { |
| 818 | function getReplacement(match, str) { |
| 819 | if (typeof replacement === 'string') { |
| 820 | return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => { |
| 821 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter |
| 822 | if (i === '$') return '$'; |
| 823 | if (i === '&') return match[0]; |
| 824 | const num = +i; |
| 825 | if (num < match.length) return match[+i]; |
| 826 | return `$${i}`; |
| 827 | }); |
| 828 | } else { |
| 829 | return replacement(...match, match.index, str, match.groups); |
| 830 | } |
| 831 | } |
| 832 | function matchAll(re, str) { |
| 833 | let match; |
| 834 | const matches = []; |