0

I am writing a regex to match any object and the simplest I could think of is /./g. I tested this using javascript by two possible methods(one with RegExp object and another using normal syntax).

For some reason, the regex doesn't work as expected while using the RegExp object. Please check the below code snippet and help me to understand why RegExp object returns false for 0 and 5.

var regex=new RegExp(".","g");
var objectsArray=["Hello","$234",0, 23, 234,"Text",5];
for(object of objectsArray){
  console.log("Current Value : " + object);
  console.log("Normal Regex  Result : " + /./g.test(object));
  console.log("RegExp Object Result : " + regex.test(object))
}
JSN
  • 2,035
  • 13
  • 27

0 Answers0