Skip to content

Regex replace w/ $ literal #82935

Closed
Closed

Description

Issue Type: Bug

  1. Create a new file with the contents "var(--foo-bar)"
  2. Find/Replace: var\(--([a-z\-]+)\) with $$1. Results in replacement with $$1 literally. \$$1 results in \$1 literally. $1 properly results in foo-bar.

There seems to be no combination that will result in replacing w/ $foo-bar

VS Code version: Code 1.39.2 (6ab5985, 2019-10-15T15:33:00.827Z)
OS version: Darwin x64 19.0.0

System Info
Item Value
CPUs Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz (8 x 2700)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: enabled
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_deferred_display_list: disabled_off
skia_renderer: disabled_off
surface_synchronization: enabled_on
video_decode: enabled
viz_display_compositor: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 3
Memory (System) 16.00GB (0.24GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (36)
Extension Author (truncated) Version
glo-vs-code Axo 0.1.2
ng-template Ang 0.802.3
vscode-color ans 0.4.5
npm-intellisense chr 1.3.0
vscode-eslint dba 1.9.1
xml Dot 2.5.0
gitlens eam 10.1.1
tslint eg2 1.0.44
vscode-npm-script eg2 0.3.9
prettier-vscode esb 2.3.0
auto-rename-tag for 0.1.0
todo-tree Gru 0.0.160
Angular2 joh 8.1.1
graphql-for-vscode kum 1.15.1
dotenv mik 1.0.1
vscode-docker ms- 0.8.1
mssql ms- 1.7.0
cpptools ms- 0.26.0
debugger-for-chrome msj 4.12.0
vscode-ios-common-files Ort 1.0.5
material-icon-theme PKi 3.9.1
swaggitor qns 0.1.1
ruby reb 0.25.3
java red 0.51.0
vscode-yaml red 0.5.3
jenkinsfile-support sec 0.1.0
code-settings-sync Sha 3.4.3
nativescript Tel 0.10.2
vscode-status-bar-format-toggle tom 2.0.0
vscodeintellicode Vis 1.2.0
vscode-java-debug vsc 0.22.0
vscode-java-dependency vsc 0.6.0
vscode-java-pack vsc 0.8.0
vscode-java-test vsc 0.20.0
vscode-maven vsc 0.19.1
propertylist zho 0.0.2

(2 theme extensions excluded)

Activity

  1. ArturoDent commented on Oct 20, 2019

    @ArturoDent

    Try $$$1

    In .NET, JavaScript, VBScript, XRegExp, PCRE2, and std::regex you can escape the dollar sign with another dollar sign. $$ replaces with a literal dollar sign.

    From https://www.regular-expressions.info/replacecharacters.html

  2. joeflateau commented on Oct 20, 2019

    @joeflateau
    Author

    huh ArturoDent that does work. I thought I had tried that already. I'll leave this open because I would expect \$ to also work. But thank you!

  3. added
    bug
    search-replace
    on Nov 15, 2019
  4. Simran-B commented on Dec 13, 2019

    @Simran-B

    For clarity:

    Type Value
    Input var(--foo-bar)
    Find var\(--([a-z\-]+)\)
    Replace $$$1
    Output $foo-bar ✔
    Type Value
    Input var(--foo-bar)
    Find var\(--([a-z\-]+)\)
    Replace \$$1
    Output \$foo-bar ❓
    Desired $foo-bar 👍

    Should \$foo-bar be desired, then that should still be possible even if \$ is made an alternative to $$ for a literal dollar sign, using an escaped backslash:

    Type Value
    Input var(--foo-bar)
    Find var\(--([a-z\-]+)\)
    Replace \\\$$1 or \\$$$1
    Output \\$foo-bar or $foo-bar
    Desired $foo-bar or $foo-bar

    … $$1. Results in replacement with $$1 literally.

    This sounded like a bug to me. Two dollar signs should result in a literal $. The actual behavior seems to be correct in VSCode 1.41, so I assume it was either broken in a previous version but fixed or a typo in the original post.

    Type Value
    Input var(--foo-bar)
    Find var\(--([a-z\-]+)\)
    Replace $$1
    Output $1 ✔
  5. locked and limited conversation to collaborators on Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugsearch-replace

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions