I am trying to capture variable names from the variable declaration. The variables are declared and initialized in the following manner:
let URL="https://www.lipsum.com/", error, pass=true;
I have this above code in the form of a string and I want to obtain the name of the variables using RegEX.
I am using this regex expression: /let\s+([\w_$]+)(?:=.*),?/;
However, I am only getting URL in the output
const str = `let URL="https://www.lipsum.com/", error, pass=true;`;
const regex = /let\s+([\w_$]+)(?:=.*),?/;
console.log(str.match(regex));
How do I obtain the variable names URL, error, and pass from the given string?