RegExp object exec() accepts a single argument, which is the string on which to apply the pattern.
It returns an array of information about the first match or null if no match was found.
The returned array, though an instance of Array, contains two additional properties:
The first item in the array is the string that matches the entire pattern.
Any additional items represent captured groups inside the expression.
If there are no capturing groups in the pattern, then the array has only one item.
Consider the following:
var text = "this is a test test test"; var pattern = /t/gi; var matches = pattern.exec(text); console.log(matches.index); //0 console.log(matches.input); /*from w ww . ja va 2s . c om*/ console.log(matches); console.log(matches); console.log(matches);