0

Possible Duplicate:
How do you pass a variable to a Regular Expression JavaScript?

how to write a variable into a reg exp pattern?

here the pattern always is /value/i

var value = inp.val();
if(search_list[key].search(/value/i) >= 0) alert('ok');
Community
  • 1
  • 1
clarkk
  • 24,753
  • 63
  • 173
  • 296

1 Answers1

2

Instead of using the implicit literal syntax you could change to be explicit.

new RegExp(value, "i")
Quintin Robinson
  • 76,510
  • 14
  • 116
  • 132