TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript RegExp exec() Method

JavaScript RegExp exec() Methods with examples on javascript regexp methods, compile(), toSource(), test() method, toString(), exec(), @@match(), @@replace(), @@search(), @@split(), search(), match() etc.

<< Back to JAVASCRIPT

JavaScript RegExp.prototype.exec() Method

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

RegExpObject.exec( string )

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

var 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);
Test it Now

Output:

Test 1 - returned value : script

Example 2

var 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);
Test it Now

Output:

Test 2 - returned value : null

Example 3

var 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
Test it Now

Output:

Returned value : script
Returned value : language
Next TopicJavaScript RegExp




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf