-1

Given the following JavaScript code:

var res = 'text';
    var regex = new RegExp(res);

    var str = 'My text';
    if (str.match(regex)) {
      alert('found word');
    }

I need to inform RegExp that theres variable can be uppercase or lowercase. Something like this: str.match (regex / i).

John Lima
  • 85
  • 4

1 Answers1

0

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

new RegExp(res, 'i')

Is what you need.

Nathan
  • 479
  • 6
  • 13