METHOD:  String::match


object.match(regexp)

This method is used to match a specifed regular expression against a string. If one or more matches are made, an array is returned that contains all of the matches. Each entry in the array is a copy of a string that contains a match. If no match is made, a null is returned.

To perform a global match you must include the 'g' (global) flag in the regular expression and to perform a case-insensitive match you must include the 'i' (ignore case) flag.

The following code uses the match method to search the characters in the myString string for a match with the specified regular expression and displays the resulting string in the browser. Note that the 'i' flag is used to make the search case-insensitive.

Code:
myString = new String("DevGuru.com")
myRE = new RegExp("guru", "i")
results = myString.match(myRE)
for(var i =0: i < myRE.length; i++)
   {
      document.write(results[i])
   }

Output:
Guru


Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information