From http://www.w3schools.com (Copyright Refsnes Data)

JavaScript match() Method


String Object Reference JavaScript String Object

Definition and Usage

The match() method returns the matches when matching a string against a regular expression.

This method returns an array of information, or null if no match is found.

Syntax

stringObject.match(regexp)

Parameter Description
regexp Required. A regular expression object. Read more about the RegExp object


Example

Example

Perform a global, case-insensitive search for "ain":

<script type="text/javascript">

var str="The rain in SPAIN stays mainly in the plain";
var patt1=/ain/gi;
document.write(str.match(patt1));

</script>

The output of the code above will be:


Try it yourself »


String Object Reference JavaScript String Object

From http://www.w3schools.com (Copyright Refsnes Data)