EN
VS Code - text replacing using regex groups
5 points
In this short article, we would like to show how to replace some text using groups in VS Code IDE.
Simple steps:
- press
Ctrl
+F
to open search popup window, - click
▁*
button in the search popup window to enable expression mode, - click
>
button in the search popup window enable replace mode, - in Find field write some expression with groups (use brackets),
e.g.abc(\d+)abc(\d+)abc(\d+)
- in Replace field write some text using
$1
,$2
,$3
, etc. addressing groups,
e.g.$1
-$2
-$3
- click
Replace (Enter)
button,
e.g.
abc123abc456abc789
text should be replaced to123-456-789
,
abc1abc23abc456
text should be replaced to1-23-456
,
etc. - done!
In this section, we want to show how to replace double apostrophes with single apostrophes in ECMAScript imports.
In the search popup window use the following values:
xxxxxxxxxx
1
Find field:
2
^import (.*) from "(.*)";
3
4
Replace field:
5
import $1 from '$2';
Screenshot:
