JavaScript RegExp.prototype.exec() Method

17 Mar 2025 | 1 min read

The exec() method returns an array containing all the matched groups. It executes a search for a match in a specified string. If it finds a match, it returns an array. Otherwise, it returns null.

Syntax

Parameters

string : The string to be searched.

Return value

It will return the array if a match is found. Otherwise, it will return null.

Example 1

Test it Now

Output:

 Test 1 - returned value : script 

Example 2

Test it Now

Output:

 Test 2 - returned value : null 

Example 3

Test it Now

Output:

 Returned value : script Returned value : language