in Typescript, I need to expand a variable inside a regular expression to build a filter for a MongoDB query; none of the following solutions seem to be valid; only the variable "code" is expanded, not the "subCode"; suppose we have:
let code = "code1";
let subCode = "CODE2.";
const regexExpression = {code: { $in: [`${code}`, /^`${subCode}`\..*/i] }};
const newRegexExpression = new RegExp(/code: { $in: [`${code}`, /^`${subCode}`\..*/i] }/i
);
Desired result:
{ "code" : { $in : [ "code1", /^"CODE2\.".*/i ] } }
tags in the code? – Simon Lundberg Jan 05 '23 at 10:31