0

I need to remove single quotation marks from

var test = '\/'+val.text+'\/i';

in order to do a mongodb search like db.document.find({field:test}) That is, If val.text is 'hello', the find should be

db.document.find({field:/hello/i})

and not

db.document.find({field:'/hello/i'})

which wont find any field with the substring 'hello' How do I do that without using eval(test) ?

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
Fjadar
  • 1
  • 1

2 Answers2

1
// This should do it:
var test = new RegExp(val.text, "i");
forsvunnet
  • 1,238
  • 10
  • 17
0
val.text.replace("'", "");

Should do what you want.

Willem Mulder
  • 12,974
  • 3
  • 37
  • 62
  • Ah, I now understand what you want. You want to build a Regexp literal, and not a String. Forsvunnets answer should do what you want! – Willem Mulder Nov 11 '13 at 08:57