TheDeveloperBlog.com

Home | Contact Us

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

JavaScript RegExp test() Method

JavaScript RegExp test() 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.test() Method

The test() method of JavaScript executes a search for a match between a regular expression and a specified string. If the match is found, it will return true. Otherwise, it will return false.

Syntax

RegExpObject.test( string );

Parameters

string : The string to be searched.

Return value

It will return true if there is a match between the regular expression and the specified string. Otherwise, it will return false.

Example 1

var string = " Learn Javascript scripting language now ";
         var result = new RegExp( "script", "g" );
         var obj = result.test(string);
         document.write("Matching and Return value : " +  obj); 
Test it Now

Output:

Matching and Return value : true

Example 2

var string = " Learn Javascript scripting language now "
 var  result1 = new RegExp( "pushing", "g" );
         var obj1 = result1.test(string);
         document.write("<br />Matching and Return value : " +  obj1);
Test it Now

Output:

Matching and Return value : false

Example 3

var str = " Java Script is a object Oriented Scripting language ";
         var result = new RegExp( "Dependent", "g" );
         
         var ob = result.test(str);
         document.write("Match String  : " +  ob); 
         
        var  result1 = new RegExp( "object Oriented ", "g" );
          var obj = result1.test(str);
         document.write("<br />Match String : " +  obj);
Test it Now

Output:

Match String : false
Match String : true
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