Favorites

JavaScript String.prototype.match() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.match()
JavaScript String Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The match() method searches a string with a regular expression and returns the matches, or null if there are none.

Description

The match() method retrieves the result of matching the string against a regular expression. Without the g flag, it returns the first match along with its capture groups, named groups and position. With g, it returns an array of every matching substring, but no groups.

It returns null when nothing matches, so check before using the result. To get capture groups for every match, use matchAll().

A string argument is converted to a regular expression, so special characters such as . and ? keep their regex meaning; escape them, or use includes() for plain text. The index property of a non-global result tells you where the match starts. When you only need a yes or no, RegExp.prototype.test() is clearer and slightly faster.

Syntax

string.match(regexp)

Parameters

  • regexpA regular expression (a string is converted to one).

Return Value

Without the g flag, an array with the full match and capture groups (plus index and groups), or null. With g, an array of all matches, or null.

Example

const date = '2026-11-28';
const m = date.match(/(?<year>\d{4})-(\d{2})/);
console.log(m[0], m[2], m.groups.year);

console.log('a1 b22 c333'.match(/\d+/g));
console.log('abc'.match(/\d/));

Browser Support

The following information will show you the current browser support for the String.prototype.match() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee