You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"$$n" doesn't replace by literal "$n" in Regex replace (Workspace search only) #299365
Use "some_line" as the find string (the find string value doesn't matter)
Enter "$$0" as the replace string
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.
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:
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.
Activity
RedCMD commentedon Mar 5, 2026
can confirm
escaping
$1with$only partially works$$1should result in$1, but doesn'tdobbydobap commentedon Jul 18, 2026
Took a look, the workspace-search replace parser (
parseReplaceStringinreplace.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$$0comes 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 nativeString.replacecollapse 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.fix(search): keep $$ escape intact when replace has parameters (micro…