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?

1
  • 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"); Commented Mar 11, 2016 at 23:16

2 Answers 2

2
var rx = /test/i;

console.log(rx.test("das ist ein test"));
Sign up to request clarification or add additional context in comments.

Comments

1

try this:

var regex = new RegExp(/test/);

5 Comments

How is this any different than what's in the OP?
Regex is not a native JS object, but RegExp is. Running the code with this modification actually does work.
@jehna1 ah, indeed. Apologies.
Regex --> RegExp. A missing p and the e is capitalized.
Thank you. I did not know there is a native RegExp in node. I used a module and required it under the name "Regex". Seems like the module is not working fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.