0

Here's the code that declares the same pattern in two different ways

let reg = new RegExp("\d+"); // 1st way
let reg2 = /\d+/; // 2nd way
let string = "one two 100";
console.log(reg.test(string)); // false
console.log(reg2.test(string)); // true

I was reading the book "Eloquent JavaScript" and they said these two ways of declaring regex are equivalent but I don't know why the code above is producing different results.

Ritesh
  • 45
  • 6

0 Answers0