Pages

Javascript RegExp - test Method

Description:

The test method searches string for text that matches regexp. If it finds a match, it returns true; otherwise, it returns false.

Syntax:

RegExpObject.test( string );
Here is the detail of parameters:
  • string : The string to be searched

Return Value:

Returns the matched text if a match is found, and null if not.

Example:

<html>
<head>
<title>JavaScript RegExp test 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.test(str);
   document.write("Test 1 - returned value : " +  result); 

   re = new RegExp( "pushing", "g" );
   var result = re.test(str);
   document.write("<br />Test 2 - returned value : " +  result); 
</script>
</body>
</html>
This will produce following result:
Test 1 - returned value : true
Test 2 - returned value : false 
 
+JavaScript +JavaScript Frameworks Links +Javascript Development 
+JavaScript's and More, Software and Marketing +JavascriptU +JavaScriptOn 
+Javascript Problems +JavaScriptOn 
 +javaScript is a creek in West Virginia in the summe  
+enJineS +JavascriptU +Javascript Tutor   

No comments:

Flag Counter
| Copyright © 2013 Remote Tutor