Skip to content

Can't replace with regex containing lookaround that matches across linesΒ #128134

Closed
@WORMSS

Description

Issue Type: Bug

Find:

import type \{ (\w+) \}

Replace

import { $1 }

Does what you expect, and turns
import type { Test } into import { Test }
but if you use the regex which includes back references

import type \{ (\w+) \}(?=[\s\S]*(new \1\(|\b\1\.|instanceof \1\b|\b\1\())

And replace with the same

import { $1 }

import type { Test } into import { $1 }

I cannot seem to find a way to cheese the system

Test example

import { A } from './A';
import type { B } from './B';
import { C } from './C';
import type { D } from './D';
import { E } from './E';
import type { F } from './F';
import { G } from './G';
import type { H } from './H';

B();
D.hello();
instanceof F()

In-file find and replace works perfectly fine. πŸ‘
image

But the 'find in files' one breaks πŸ‘Ž
image

VS Code version: Code 1.57.1 (507ce72, 2021-06-17T13:28:07.755Z)
OS version: Windows_NT x64 10.0.19043
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Xeon(R) CPU E5-1620 v3 @ 3.50GHz (8 x 3492)
GPU Status 2d_canvas: unavailable_software
gpu_compositing: disabled_software
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: disabled_off
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: unavailable_software
webgl2: unavailable_software
Load (avg) undefined
Memory (System) 15.92GB (1.88GB free)
Process Argv --crash-reporter-id 21d722df-78c7-4ac1-bbfa-5b7156602bd2
Screen Reader no
VM 0%
Extensions (32)
Extension Author (truncated) Version
alloy-vscode cmc 0.0.1
ascii-tree-generator apr 1.2.4
markdown-preview-github-styles bie 0.2.0
npm-intellisense chr 1.3.1
bracket-pair-colorizer Coe 1.0.61
vscode-svgviewer css 2.0.0
vue-peek dar 1.0.2
vscode-eslint dba 2.1.23
java-decompiler dgi 0.0.2
vscode-ts-auto-return-type ebr 1.1.0
RunOnSave eme 0.2.0
prettier-vscode esb 8.0.1
todo-tree Gru 0.0.213
jbockle-format-files jbo 3.3.0
vscode-js-annotations lan 0.11.0
node-module-intellisense lei 1.5.0
camelcasenavigation map 1.1.3
rainbow-csv mec 1.9.1
vscode-typescript-tslint-plugin ms- 1.3.3
node-modules-resolve nau 1.0.2
uuid-generator net 0.0.4
printcode nob 3.0.0
vetur oct 0.34.1
vscode-versionlens pfl 1.0.9
java red 0.80.0
vscode-xml red 0.17.0
vscode-sort-json ric 1.20.0
gitconfig sid 2.0.1
vscode-stylelint sty 0.86.0
open-in-browser tec 2.0.0
sort-lines Tyr 1.9.0
vscode-icons vsc 11.5.0
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
pythonvspyt602:30300191
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt639:30300192
pythontb:30283811
pythonvspyt551:30311712
vspre833:30321513
pythonptprofiler:30281270
vshan820:30294714
pythondataviewer:30285071
vscus158:30321503
pythonvsuse255:30323308
vscorehov:30309549
vscod805:30301674
pythonvspyt200:30329803
binariesv615:30325510
vsccppwtct:30329789

Activity

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

Metadata

Assignees

Labels

*duplicateIssue identified as a duplicate of another issue(s)bugIssue identified by VS Code Team member as probable bugconfirmedIssue has been confirmed by VS Code Team membersearchSearch widget and operation issues

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions