In my application I have to store the function as string in datastore and load it in the runtime. RegExp matching inside the "Function" is working differently than the usual one, producing unexpected result. What is the issue here ?
var message = "I expected two hundred and three fifty ($200) and ($350) dollars from this statement";
var extractResult = (a) => {
const inputFn = new Function("val", `
const pattern = new RegExp(/\(([^)]+)\)/, "gi");
const result = val.match(pattern);
return result;
`);
return inputFn(a);
}
console.log("direct", message.match(new RegExp(/\(([^)]+)\)/, "gi")))
console.log("function",extractResult(message))
I need to get the output as same as in "direct" one. Or I just need to extract all strings inside the brackets, so for the above example, I'm expecting ["$200", "$350"]