Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The match() method of String values retrieves the result of matching this string against a regular expression.
A regular expression object, or any object that has a Symbol.match method.
If regexp is not a RegExp object and does not have a Symbol.match method, it is implicitly converted to a RegExp by using new RegExp(regexp).
If you don't give any parameter and use the match() method directly, you will get an Array with an empty string: [""], because this is equivalent to match(/(?:)/).
An Array whose contents depend on the presence or absence of the global (g) flag, or null if no matches are found.
The implementation of String.prototype.match doesn't do much other than calling the Symbol.match method of the argument with the string as the first parameter. The actual implementation comes from RegExp.prototype[Symbol.match]().
For more information about the semantics of match() when a regex is passed, see RegExp.prototype[Symbol.match]().
In the following example, match() is used to find "Chapter" followed by one or more numeric characters followed by a decimal point and numeric character zero or more times.
The regular expression includes the i flag so that upper/lower case differences will be ignored.
In the match result above, 'see Chapter 3.4.5.1' is the whole match. 'Chapter 3.4.5.1' was captured by (chapter \d+(\.\d)*). '.1' was the last value captured by (\.\d). The index property (22) is the zero-based index of the whole match. The input property is the original string that was parsed.
The following example demonstrates the use of the global flag and ignore-case flag with match(). All letters A through E and a through e are returned, each its own element in the array.
Note: See also String.prototype.matchAll() and Advanced searching with flags.
In browsers which support named capturing groups, the following code captures "fox" or "cat" into a group named animal:
If an object has a Symbol.match method, it can be used as a custom matcher. The return value of Symbol.match becomes the return value of match().
When the regexp parameter is a string or a number, it is implicitly converted to a RegExp by using new RegExp(regexp).
This may have unexpected results if special characters are not properly escaped.
This is a match because . in a regex matches any character. In order to make it only match specifically a dot character, you need to escape the input.
| ECMAScript® 2027 Language Specification # sec-string.prototype.match |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.