String.match()

JavaScript1.2+, JScript3.0+ NES3+, Nav4+, IE4+ Syntax

							string.match(regexpression)

Description

The match() method of an instance of the String object searches the string in which it is invoked for the regular expression passed to the method. The regular expression is made up of a pattern and flags that dictate what is to be matched. The method returns an array containing the matches found in the string.

Tip

See the reference entry for RegExp for a list of the patterns and flags that can be used to create a regular expression.

Example

Listing 6.245 creates an instance of the String object and tries to match instances that contain a space followed by some characters. If any matches were returned into the array, they are ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.