English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.g
If the regular expression contains
If the regular expression does not containg
If 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.
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‹/›
All browsers fully support the match() method:
Method | |||||
match() | Is | Is | Is | Is | Is |
Parameter | Description |
---|---|
regex | Regular Expression Object |
Return Value: | An array containing the matches, each match is an item, or null if no matches are found |
---|---|
JavaScript Version: | ECMAScript 1 |
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: