English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JS DOM reference manual

 JavaScript String Object

match()JavaScript String match() method

This method searches for matches with the regular expression in the string and then returns the matches as an Array object.gIf the regular expression contains

If the regular expression does not containgIf the modifier (global search) is used, this method will only return the first match in the string.

If there is no match, this method returns null.

You can find more information inRegExp tutorialandRegExp object referenceLearn more about regular expressions.

Syntax:

string.match(regex)
var str = 'POLLUTION: Air Pollution is the introduction of chemicals to the atmosphere'
var reg = str.match(/ion/g);
Test and see‹/›

Browser Compatibility

All browsers fully support the match() method:

Method
match()IsIsIsIsIs

Parameter Value

ParameterDescription
regexRegular Expression Object

Technical Details

Return Value:An array containing the matches, each match is an item, or null if no matches are found
JavaScript Version:ECMAScript 1

More Examples

The following examples demonstrate the use of global and case-insensitive flags with match():

var str = 'POLLUTION: Air Pollution is the introduction of chemicals to the atmosphere'
var reg = str.match(/ion/gi);
Test and see‹/›

Calculate the number of vowels in a string:

Enter some text in the input field to display the number of vowels:

Voice:

 JavaScript String Object