0

I have a problem with this code:

var regex = new Regex(/test/); console.log(regex.test("das ist ein test")); // false??

In fact I'm simply trying, to search a string in a string. It should be case insensitive. But none of my tried regexes worked yet.

Does someone have a solution?

  • You should use either native regex syntax: `var regex = /test/;` or (in this case unnecessary) the RegExp constructor with a **string** argument: `var regex = new RegExp("test");` – Pointy Mar 11 '16 at 23:16

2 Answers2

2
var rx = /test/i;

console.log(rx.test("das ist ein test"));
Michael Mikowski
  • 1,269
  • 1
  • 10
  • 21
1

try this:

var regex = new RegExp(/test/);
raszpi
  • 100
  • 1
  • 8