Skip to content

"$$n" doesn't replace by literal "$n" in Regex replace (Workspace search only) #299365

Description

@VelpaChallenger

Type: Bug

  1. Use "some_line" as the find string (the find string value doesn't matter)
  2. Enter "$$0" as the replace string
  3. Apply replace

"some_line" will be replaced with "$$0", instead of "$0". This issue only applies to workspace search (Ctrl+Shift+F). It works fine when replacing in the opened file editor. Also, it seems this issue was already reported (but closed without further investigation) in #82935. I read https://github.com/microsoft/vscode/wiki/Search-Issues, and I imagine the difference has to do with the engines used. However, it would seem that all Rust, PCRE2 and JS engines interpret "$$0" as "$0", so the cause may be elsewhere.

I tried code --disable-extensions, and I was still able to reproduce the issue.

I can trace the issue back to at least 1.105.1.

Image

VS Code version: Code 1.111.0-insider (user setup) (98dc3fd, 2026-03-04T11:48:18-05:00)
OS version: Windows_NT x64 10.0.26100
Modes:

Activity

  1. RedCMD commented on Mar 5, 2026

    @RedCMD
    Contributor

    can confirm

    escaping $1 with $ only partially works
    $$1 should result in $1, but doesn't

  2. dobbydobap commented on Jul 18, 2026

    @dobbydobap
    Contributor

    Took a look, the workspace-search replace parser (parseReplaceString in replace.ts) has cases for $0, $`, $', and $1–$99, but nothing for $$, so it never gets flagged as a parameter and ends up inserted literally ,which is why $$0 comes out as $$0.

    The in-editor find/replace already treats $$ as an escaped $ (replacePattern.ts), so the two have just drifted apart.

    Handling $$ in the same branch as $` / $' lets the native String.replace collapse it, giving $$0 → $0 (and $$1 → $1) matching the editor and normal regex-replace behaviour. Happy to put up a PR with a regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions