C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript RegExp.prototype.exec() MethodThe 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. SyntaxRegExpObject.exec( string ) Parametersstring : The string to be searched. Return valueIt will return the array if a match is found. Otherwise, it will return null. Example 1var str = "Javascript is an interesting scripting language"; var re = new RegExp( "script", "g" ); var result = re.exec(str); document.writeln("Test 1 - returned value : " + result); Output: Test 1 - returned value : script Example 2var str = "Javascript is an interesting scripting language"; var obj = new RegExp( "output", "g" ); var res = obj.exec(str); document.writeln("<br />Test 2 - returned value : " + res); Output: Test 2 - returned value : null Example 3var string = "Javascript is an interesting scripting language"; var obj1 = new RegExp( "script", "g" ); var result1 = obj1.exec(string); document.write("Returned value : " + result1); var obj = new RegExp( "language", "g" ); var res = obj.exec(string); document.write("<br />Returned value : " + res); // use,document.write Output: Returned value : script Returned value : language
Next TopicJavaScript RegExp
|