0

I do have the following string:

"/^\d{4}$/"

which I want to convert to a RegExp to use the test method on it. However, simply doing :

var r = new RegExp("/^\d{4}$/") // returns : /\/^\d{4}$\//
r.test("4800") // returns false

isn't working.

I also tried the following :

var r = /^\d{4}$/
r.test("4800") // returns true

which is working

What am I missing here ? How to have it working in the first case with a string.

Scipion
  • 11,449
  • 19
  • 74
  • 139

0 Answers0