3

If you invoke the test method on a RegExp, does that somehow "complete" the RegExp. A subsequent exec invocation appears to no longer work.

var isoDateRegEx = /(\d{4})-(\d{2})-(\d{2})/g;
var isoDateString = '2001-01-01';

if (!isoDateRegEx.test(isoDateString)) {
  throw 'isoDateString must be in ISO 8601 format.';
}

var captures = isoDateRegEx.exec(isoDateString); // null
Ben Aston
  • 53,718
  • 65
  • 205
  • 331

0 Answers0