javascript - how to pass a variable to a regex -
i have find statement this
collsession.find({"venue.type": /.*mt.*/}).toarray(function (err, _clssession) { console.log(_clssession); });
it giving answer.but need value of variable instead of harcoded value mt. how achieve ? thanks.
update tried "/."+searchterm+"./" not working.
instead of using inline syntax create regular expression, can use regexp object create 1 based on string
var searchphrase = "mt"; var regularexpression = new regexp(".*" + searchphrase + ".*"); collsession.find({"venue.type": regularexpression}) [...]