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}) [...] 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -