0

The test function of the regular expression returns an invalid value when the 'g' flag is present.

Example:

var regExpArh = /(\.rar|\.zip|\.7z)$/gi;
var s = "55.7z";
regExpArh.test(s); // return true
regExpArh.test(s); // return false
regExpArh.test(s); // return true
regExpArh.test(s); // return false

Why?

Mohammad Usman
  • 34,173
  • 19
  • 88
  • 85

1 Answers1

0

See this documentation.

If the regex has the global flag set, test() will advance the lastIndex of the regex. A subsequent use of test() will start the search at the substring of str specified by lastIndex (exec() will also advance the lastIndex property).

Ward
  • 2,731
  • 18
  • 26