C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript RegExp.prototype.test() MethodThe 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. SyntaxRegExpObject.test( string ); Parametersstring : The string to be searched. Return valueIt will return true if there is a match between the regular expression and the specified string. Otherwise, it will return false. Example 1var string = " Learn Javascript scripting language now "; var result = new RegExp( "script", "g" ); var obj = result.test(string); document.write("Matching and Return value : " + obj); Output: Matching and Return value : true Example 2var 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); Output: Matching and Return value : false Example 3var 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); Output: Match String : false Match String : true
Next TopicJavaScript RegExp
|