The exec method searches for a text string matched by a regular expression. If a match is found, the resulting array is returned; otherwise, null is returned.
Grammar
RegExpObject.exec( string );
Here are the details of the parameters:
Return value:
Example:
<html> <head> <title>JavaScript RegExp exec Method</title> </head> <body> <script type="text/javascript"> var str = "Javascript is an interesting scripting language"; var re = new RegExp( "script", "g" ); var result = re.exec(str); document.write("Test 1 - returned value : " + result); re = new RegExp( "pushing", "g" ); var result = re.exec(str); document.write("<br />Test 2 - returned value : " + result); </script> </body> </html>
This will produce the following results:
Test 1 - returned value : script Test 2 - returned value : null