microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.94k stars 28.77k forks source link

Regex Find/Replace with named capture groups #195724

Open joshuaking-madtech opened 11 months ago

joshuaking-madtech commented 11 months ago

Type: Bug

The replace field in the tool fails to parse most syntax related to regex substitutions beyond the basic numbered capture groups. There are several issues opened for closely related problems with find replace that are probably the same issue (incomplete/broken implementation of regex in the replace field) but they're not an exact match.

To Reproduce: Create a find regex with a named capture group that should match with the find/replace tool bound to ctrl+f. E.g.:

text in file:    beforetextToMatchAndCaptureafter
find:    before(?<myNamedGroup>textToMatchAndCapture)after
replace:    $<myNamedGroup>
expected:    the captured text between the (), literally "textToMatchAndCapture"
actual:    the literal $<myNamedGroup>

related: $1 does the substitution correctly.

VS Code version: Code 1.82.0 (8b617bd08fd9e3fc94d14adb8d358b56e3f72314, 2023-09-06T22:07:18.759Z) OS version: Linux x64 5.10.0-25-amd64 Modes:

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 9 7950X 16-Core Processor (8 x 4500)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|0, 0, 0| |Memory (System)|7.72GB (4.38GB free)| |Process Argv|--unity-launch --crash-reporter-id 5d647bc9-1f58-4167-858f-756fddfd1cc1| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|gnome| |XDG_CURRENT_DESKTOP|GNOME| |XDG_SESSION_DESKTOP|gnome| |XDG_SESSION_TYPE|wayland|
Extensions (22) Extension|Author (truncated)|Version ---|---|--- vscode-markdownlint|Dav|0.52.0 gitlens|eam|14.4.0 terraform-autocomplete|erd|0.0.8 prettier-vscode|esb|10.1.0 copilot|Git|1.126.0 copilot-chat|Git|0.7.1 vscode-pull-request-github|Git|0.72.0 terraform|has|2.28.2 Ionide-fsharp|Ion|7.15.0 TFS|mat|0.0.3 vscode-azureterraform|ms-|0.3.2 csharp|ms-|2.6.24 dotnet-interactive-vscode|ms-|1.0.4461040 vscode-dotnet-pack|ms-|1.0.12 vscode-dotnet-runtime|ms-|1.8.1 jupyter|ms-|2023.8.1002501831 jupyter-keymap|ms-|1.1.2 jupyter-renderers|ms-|1.0.17 vscode-jupyter-cell-tags|ms-|0.1.8 vscode-jupyter-slideshow|ms-|0.1.5 azure-account|ms-|0.11.6 vscode-conventional-commits|viv|1.25.0
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256859 vslsvsres303:30308271 vserr242:30382549 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263cf:30335440 vscod805cf:30301675 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593:30376534 pythonvs932:30410667 py29gd2263:30856252 vscaat:30438848 vsclangdf:30486550 c4g48928:30535728 dsvsc012:30540252 pynewext54:30695312 azure-dev_surveyone:30548225 2e4cg342:30602488 89544117:30613380 a9j8j154:30646983 showlangstatbar:30737416 0bi6i642:30841073 03d35959:30757346 pythonfmttext:30731395 fixshowwlkth:30771522 showindicator:30805244 pythongtdpath:30769146 i26e3531:30792625 pythonnosmt12:30797651 pythonidxptcf:30805731 pythonnoceb:30805159 copilotsettingt:30859503 dsvsc013:30795093 dsvsc014:30804076 diffeditorv2:30821572 dsvsc015:30845448 pythonregdiagcf:30859692 ```
VSCodeTriageBot commented 11 months ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.83.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

joshuaking-madtech commented 11 months ago

No change on 1.83.1

ArturoDent commented 11 months ago

See (Backlog Cnadidate): https://github.com/microsoft/vscode/issues/127657

IllusionMH commented 11 months ago

I see that issue is closed, but don't see when/whi/why. Is it still really in the backlog of closed?

VSCodeTriageBot commented 9 months ago

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

VSCodeTriageBot commented 8 months ago

:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

PieterjanDeClippel commented 7 months ago

@joshuaking-madtech

You should use the following replace (curly braces)

text in file:    beforetextToMatchAndCaptureafter
find:    before(?<myNamedGroup>textToMatchAndCapture)after
replace:    ${myNamedGroup}

This used to work 2 weeks ago, however it seems something went wrong in the past weeks. Created an issue for it

ArturoDent commented 7 months ago

@PieterjanDeClippel I don't remember named capture groups ever working in vscode.

You can find the commit that botched the feature by doing this:

Finally, to help us narrow down what change caused the issue, please run the following command 
to find the build. It will start previous releases of VS Code insiders to see where the 
regression was introduced:

* npx --yes vscode-bisect@latest  (just leave it blank where it asks for commits to start)
* follow the instructions until you found the offending build
* report back the commit range in this issue

from https://github.com/microsoft/vscode/issues/182758#issuecomment-1551500597