I have regex which I have tested on regex101 however when I use the same in nodejs it does not replace the newlines. The regex is /([ ]*\n)+/gm. It is supposed to replace multiple newlines with a single newline. The code is as follows. This code is a part of my vscode extension. Can someone tell me what I am doing wrong?
function format(str) {
const regex = /([ ]*\n)+/gm;
const subst = `\n`;
const result = str.replace(regex, subst);
return result;
}
function format(str) {
const regex = /([ ]*\n)+/gm;
const subst = `\n`;
const result = str.replace(regex, subst);
return result;
}
console.log(format(`abc
d
s
s`));