JavaScript » String » match


This method is used to match a specified 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.


myString = new String("")
myRE = new RegExp("guru", "i")
results = myString.match(myRE)
for(var i =0; i < results.length; i++)

This example 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.