Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search.
exec(string)
string
The String object or string literal on which to perform the search.
An array containing the entire match result and any parentheses-captured matched results; null if no match is found.
The array has extra properties:
index
The 0-based index of the match in the string.
input
The original string that was matched against.
groups
An object of named capturing groups whose keys are the names and whose values are the capturing group results; undefined if no named capturing groups were defined.
/[a-z]/.exec('abc')
["a"]
/(?[\d-]+)/ .exec('mobile: 123-45-67').groups.phone
"123-45-67"