I just copied the text you posted and used it as string and assumed you want to extract the content in the brackets. (path/to/image)
when I run this script:
const regex = /\!\[\[(.*)\]\]/gmi;
const str = `I need to get all the images with this formatting : ![[path/to/image]]`;
const subst = `$1`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
alert("Substitution result: " + result);
I may be wrong, but here’s my take. Unlike regex101, which is a testing tool, here you are encoding the content into a string in code, so you are escaping the slash first, and then that escaped slash is then available to escape the bracket when the string is interpreted as it is parsed sequentially rather than as a group.
const regexp = RegExp('\\\[\\[.*?\\]\\]','gmi');
let images;
while ((images = regexp.exec(draft.content)) !== null)
{
images.forEach(path => {alert(path)});
}