Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode regex find/replace replace characters inside string

I want to replace all instances of

() => import('@/components/something/Something')

with

() => import(/* webpackChunkName: "components--something--Something" */ '@/components/something/Something')

So far I have this find/replace regex

Find: \(\) => import\('(.+?)'\)

Replace: () => import(/* webpackChunkName: "$1" */ '$1')

Which replaces:

() => import('@/components/something/Something')

with

() => import(/* webpackChunkName: "@/components/something/Something" */ '@/components/something/Something')

My problem is that I don't know how to replace the "@" and "/" characters

Do I need to execute two find/replace queries or can it be done with a single one? I want to remove the "@" entirely and replace the "/" by "--"

Any help much appreciated!

Thanks

like image 952
vesperknight Avatar asked Nov 29 '25 16:11

vesperknight


1 Answers

With two find/replace:

find: (\(\) => import\()'@/([^']*)'\)
replace: $1/* webpackChunkName: "$2" */  '@/$2')

demo

and

find: ((?:\G(?!^)|\(\) => import\(/\*)[^/*]*)/
replace: $1--

demo

like image 120
Casimir et Hippolyte Avatar answered Dec 02 '25 06:12

Casimir et Hippolyte