In VS Code, is there a way to use a regular expression to find all statements which use var
to declare a variable that assigns a value using require
, and then replace just the var
with const
?
I have tried searching and I’m unable to find an answer.
This is the attempt at the regex (this part works): var[ 0-9a-zA-Z]*= require
It is the search and replace portion of just a part of the match where I am unsure how to do it, or if it is possible.
I’ve set up a StackBlitz.
In this screenshot, I’m trying to replace
var zlib = require('zlib');
by
const zlib = require('zlib');