The JavaScript RegExp exec() method is used to get an array containing all the matched groups for a specified string.
Syntax:
RegExpObject.exec(string)
Parameters:
string: It represents the string to be searched.
Return:
An array containing all the matched groups for a given string.
Example:
<!DOCTYPE html>
<html>
<body>
<script>
var string = "HELLO WORLD";
var regExObj = new RegExp( "HELLO", "g" );
var print = regExObj.exec(string);
document.write("Returned value : " + print);
</script>
</body>
</html>