Title: `$1`, `$&` in string replacements for RegExp `find` are not expanded · Issue #117 · unplugin/unplugin-replace · GitHub
Open Graph Title: `$1`, `$&` in string replacements for RegExp `find` are not expanded · Issue #117 · unplugin/unplugin-replace
X Title: `$1`, `$&` in string replacements for RegExp `find` are not expanded · Issue #117 · unplugin/unplugin-replace
Description: Describe the bug The README for options.values states: "If it's a string, it will replace the substring matched by pattern. A number of special replacement patterns are supported". However, transform passes string replacements through St...
Open Graph Description: Describe the bug The README for options.values states: "If it's a string, it will replace the substring matched by pattern. A number of special replacement patterns are supported". However, transfo...
X Description: Describe the bug The README for options.values states: "If it's a string, it will replace the substring matched by pattern. A number of special replacement patterns are supported". Ho...
Opengraph URL: https://github.com/unplugin/unplugin-replace/issues/117
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`$1`, `$&` in string replacements for RegExp `find` are not expanded","articleBody":"### Describe the bug\n\nThe README for `options.values` states: \"If it's a string, it will replace the substring matched by pattern. A number of special replacement patterns are supported\". However, `transform` passes string replacements through `String(ensureFunction(finalReplacement)(id, match))`, which returns the string verbatim without expanding `$1`, `$&`, `$\u003cname>`, or `$$`.\n\n```js\n// repro.mjs\nimport Replace from 'unplugin-replace/rollup'\n\nconst plugin = Replace({\n values: [{ find: /process\\.env\\.(\\w+)/g, replacement: 'import.meta.env.$1' }],\n})\n\nconst res = await plugin.transform.handler.call(\n {},\n 'f(process.env.API_URL)',\n '/src/a.js',\n)\nconsole.log(res.code)\n```\n\nRunning `node repro.mjs`:\n\nActual output:\n\n```js\nf(import.meta.env.$1)\n```\n\nExpected output (as with `String.prototype.replace`):\n\n```js\nf(import.meta.env.API_URL)\n```\n\n### Reproduction\n\nhttps://gist.github.com/trackoor/f81e40bdea191f6e323b0e544f0f2cc3\n\n### System Info\n\n```Shell\nSystem:\n OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)\n CPU: (64) x64 Intel(R) Xeon(R) CPU @ 2.80GHz\n Shell: 5.2.15 - /bin/bash\nBinaries:\n Node: 26.13.0\n npm: 11.20.0\nnpmPackages:\n unplugin-replace: 0.9.1 (also tested on main 8d4c2e2)\n```\n\n### Used Package Manager\n\nnpm\n\n### Validations\n\n- [x] Follow our [Code of Conduct](https://github.com/antfu/.github/blob/main/CODE_OF_CONDUCT.md)\n- [x] Read the [Contributing Guide](https://github.com/antfu/contribute).\n- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.\n- [x] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.\n- [x] The provided reproduction is a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.\n\nCredit: https://ucsbplse.github.io/\n","author":{"url":"https://github.com/trackoor","@type":"Person","name":"trackoor"},"datePublished":"2026-11-15T06:07:51Z","url":"https://github.com/unplugin/unplugin-replace/issues/117"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7236c63c-782f-38e9-5f1f-2c7efa4c3a5e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE9E:F5AA9:2AF2AA3:3AA65DE:6B00546A |
| html-safe-nonce | 7dbdf80438cd161dc60c295031190dc692b841259ae87ffca7288f9b61fa2f13 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTlFOkY1QUE5OjJBRjJBQTM6M0FBNjVERTo2QjAwNTQ2QSIsInZpc2l0b3JfaWQiOiIzMDAwNzgxMDUzNjI0NTM2MTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1d653a3d177f8534b2c11bc122bb741d94ce12bfc0e983ea0aa79edfc4d211a7 |
| hovercard-subject-tag | issue:6400707043 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/unplugin/unplugin-replace/117/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c522e49eddc975f9499fb593314c3354ed10215d7d73f7934577cd6957df2d4e/unplugin/unplugin-replace/issues/117 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c522e49eddc975f9499fb593314c3354ed10215d7d73f7934577cd6957df2d4e/unplugin/unplugin-replace/issues/117 |
| og:image:alt | Describe the bug The README for options.values states: "If it's a string, it will replace the substring matched by pattern. A number of special replacement patterns are supported". However, transfo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trackoor |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/unplugin/unplugin-replace git https://github.com/unplugin/unplugin-replace.git |
| octolytics-dimension-user_id | 143585159 |
| octolytics-dimension-user_login | unplugin |
| octolytics-dimension-repository_id | 766209113 |
| octolytics-dimension-repository_nwo | unplugin/unplugin-replace |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 766209113 |
| octolytics-dimension-repository_network_root_nwo | unplugin/unplugin-replace |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width